blob: 69230d685538c1393b91443ac71738a7d695cedc [file] [log] [blame]
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +02001/*
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
13#ifndef __MACH_IOMMU_H
14#define __MACH_IOMMU_H
15
16struct iotlb_entry {
17 u32 da;
18 u32 pa;
19 u32 pgsz, prsvd, valid;
20 union {
21 u16 ap;
22 struct {
23 u32 endian, elsz, mixed;
24 };
25 };
26};
27
28struct iommu {
29 const char *name;
30 struct module *owner;
31 struct clk *clk;
32 void __iomem *regbase;
33 struct device *dev;
34
35 unsigned int refcount;
36 struct mutex iommu_lock; /* global for this whole object */
37
38 /*
39 * We don't change iopgd for a situation like pgd for a task,
40 * but share it globally for each iommu.
41 */
42 u32 *iopgd;
43 spinlock_t page_table_lock; /* protect iopgd */
44
45 int nr_tlb_entries;
46
47 struct list_head mmap;
48 struct mutex mmap_lock; /* protect mmap */
49
50 int (*isr)(struct iommu *obj);
51
52 void *ctx; /* iommu context: registres saved area */
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +000053 u32 da_start;
54 u32 da_end;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020055};
56
57struct cr_regs {
58 union {
59 struct {
60 u16 cam_l;
61 u16 cam_h;
62 };
63 u32 cam;
64 };
65 union {
66 struct {
67 u16 ram_l;
68 u16 ram_h;
69 };
70 u32 ram;
71 };
72};
73
74struct iotlb_lock {
75 short base;
76 short vict;
77};
78
79/* architecture specific functions */
80struct iommu_functions {
81 unsigned long version;
82
83 int (*enable)(struct iommu *obj);
84 void (*disable)(struct iommu *obj);
Kanigeri, Hariddfa9752010-05-24 02:01:51 +000085 void (*set_twl)(struct iommu *obj, bool on);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020086 u32 (*fault_isr)(struct iommu *obj, u32 *ra);
87
88 void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
89 void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
90
91 struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
92 int (*cr_valid)(struct cr_regs *cr);
93 u32 (*cr_to_virt)(struct cr_regs *cr);
94 void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
95 ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
96
97 u32 (*get_pte_attr)(struct iotlb_entry *e);
98
99 void (*save_ctx)(struct iommu *obj);
100 void (*restore_ctx)(struct iommu *obj);
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700101 ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200102};
103
104struct iommu_platform_data {
105 const char *name;
106 const char *clk_name;
107 const int nr_tlb_entries;
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +0000108 u32 da_start;
109 u32 da_end;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200110};
111
112#if defined(CONFIG_ARCH_OMAP1)
113#error "iommu for this processor not implemented yet"
114#else
Tony Lindgrence491cf2009-10-20 09:40:47 -0700115#include <plat/iommu2.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200116#endif
117
118/*
119 * utilities for super page(16MB, 1MB, 64KB and 4KB)
120 */
121
122#define iopgsz_max(bytes) \
123 (((bytes) >= SZ_16M) ? SZ_16M : \
124 ((bytes) >= SZ_1M) ? SZ_1M : \
125 ((bytes) >= SZ_64K) ? SZ_64K : \
126 ((bytes) >= SZ_4K) ? SZ_4K : 0)
127
128#define bytes_to_iopgsz(bytes) \
129 (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
130 ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
131 ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
132 ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
133
134#define iopgsz_to_bytes(iopgsz) \
135 (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
136 ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
137 ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
138 ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
139
140#define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
141
142/*
143 * global functions
144 */
145extern u32 iommu_arch_version(void);
146
147extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
148extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
149
150extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
Kanigeri, Hariddfa9752010-05-24 02:01:51 +0000151extern void iommu_set_twl(struct iommu *obj, bool on);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200152extern void flush_iotlb_page(struct iommu *obj, u32 da);
153extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
154extern void flush_iotlb_all(struct iommu *obj);
155
156extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
157extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
158
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +0000159extern int iommu_set_da_range(struct iommu *obj, u32 start, u32 end);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200160extern struct iommu *iommu_get(const char *name);
161extern void iommu_put(struct iommu *obj);
162
163extern void iommu_save_ctx(struct iommu *obj);
164extern void iommu_restore_ctx(struct iommu *obj);
165
166extern int install_iommu_arch(const struct iommu_functions *ops);
167extern void uninstall_iommu_arch(const struct iommu_functions *ops);
168
169extern int foreach_iommu_device(void *data,
170 int (*fn)(struct device *, void *));
171
Hiroshi DOYU14e0e672009-08-28 10:54:41 -0700172extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
173extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200174
175#endif /* __MACH_IOMMU_H */