2 * omap iommu: main structures
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
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.
13 #ifndef __MACH_IOMMU_H
14 #define __MACH_IOMMU_H
19 u32 pgsz
, prsvd
, valid
;
23 u32 endian
, elsz
, mixed
;
32 void __iomem
*regbase
;
35 unsigned int refcount
;
36 struct mutex iommu_lock
; /* global for this whole object */
39 * We don't change iopgd for a situation like pgd for a task,
40 * but share it globally for each iommu.
43 spinlock_t page_table_lock
; /* protect iopgd */
47 struct list_head mmap
;
48 struct mutex mmap_lock
; /* protect mmap */
50 int (*isr
)(struct iommu
*obj
);
52 void *ctx
; /* iommu context: registres saved area */
77 /* architecture specific functions */
78 struct iommu_functions
{
79 unsigned long version
;
81 int (*enable
)(struct iommu
*obj
);
82 void (*disable
)(struct iommu
*obj
);
83 void (*set_twl
)(struct iommu
*obj
, bool on
);
84 u32 (*fault_isr
)(struct iommu
*obj
, u32
*ra
);
86 void (*tlb_read_cr
)(struct iommu
*obj
, struct cr_regs
*cr
);
87 void (*tlb_load_cr
)(struct iommu
*obj
, struct cr_regs
*cr
);
89 struct cr_regs
*(*alloc_cr
)(struct iommu
*obj
, struct iotlb_entry
*e
);
90 int (*cr_valid
)(struct cr_regs
*cr
);
91 u32 (*cr_to_virt
)(struct cr_regs
*cr
);
92 void (*cr_to_e
)(struct cr_regs
*cr
, struct iotlb_entry
*e
);
93 ssize_t (*dump_cr
)(struct iommu
*obj
, struct cr_regs
*cr
, char *buf
);
95 u32 (*get_pte_attr
)(struct iotlb_entry
*e
);
97 void (*save_ctx
)(struct iommu
*obj
);
98 void (*restore_ctx
)(struct iommu
*obj
);
99 ssize_t (*dump_ctx
)(struct iommu
*obj
, char *buf
, ssize_t len
);
102 struct iommu_platform_data
{
104 const char *clk_name
;
105 const int nr_tlb_entries
;
108 #if defined(CONFIG_ARCH_OMAP1)
109 #error "iommu for this processor not implemented yet"
111 #include <plat/iommu2.h>
115 * utilities for super page(16MB, 1MB, 64KB and 4KB)
118 #define iopgsz_max(bytes) \
119 (((bytes) >= SZ_16M) ? SZ_16M : \
120 ((bytes) >= SZ_1M) ? SZ_1M : \
121 ((bytes) >= SZ_64K) ? SZ_64K : \
122 ((bytes) >= SZ_4K) ? SZ_4K : 0)
124 #define bytes_to_iopgsz(bytes) \
125 (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
126 ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
127 ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
128 ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
130 #define iopgsz_to_bytes(iopgsz) \
131 (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
132 ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
133 ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
134 ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
136 #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
141 extern u32
iommu_arch_version(void);
143 extern void iotlb_cr_to_e(struct cr_regs
*cr
, struct iotlb_entry
*e
);
144 extern u32
iotlb_cr_to_virt(struct cr_regs
*cr
);
146 extern int load_iotlb_entry(struct iommu
*obj
, struct iotlb_entry
*e
);
147 extern void iommu_set_twl(struct iommu
*obj
, bool on
);
148 extern void flush_iotlb_page(struct iommu
*obj
, u32 da
);
149 extern void flush_iotlb_range(struct iommu
*obj
, u32 start
, u32 end
);
150 extern void flush_iotlb_all(struct iommu
*obj
);
152 extern int iopgtable_store_entry(struct iommu
*obj
, struct iotlb_entry
*e
);
153 extern size_t iopgtable_clear_entry(struct iommu
*obj
, u32 iova
);
155 extern struct iommu
*iommu_get(const char *name
);
156 extern void iommu_put(struct iommu
*obj
);
158 extern void iommu_save_ctx(struct iommu
*obj
);
159 extern void iommu_restore_ctx(struct iommu
*obj
);
161 extern int install_iommu_arch(const struct iommu_functions
*ops
);
162 extern void uninstall_iommu_arch(const struct iommu_functions
*ops
);
164 extern int foreach_iommu_device(void *data
,
165 int (*fn
)(struct device
*, void *));
167 extern ssize_t
iommu_dump_ctx(struct iommu
*obj
, char *buf
, ssize_t len
);
168 extern size_t dump_tlb_entries(struct iommu
*obj
, char *buf
, ssize_t len
);
170 #endif /* __MACH_IOMMU_H */