blob: 68b5f0362f356a0adb402706fec5378828d716ae [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
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030028struct omap_iommu {
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020029 const char *name;
30 struct module *owner;
31 struct clk *clk;
32 void __iomem *regbase;
33 struct device *dev;
David Cohend594f1f2011-02-16 19:35:51 +000034 void *isr_priv;
Ohad Ben-Cohene7f10f02011-09-13 15:26:29 -040035 struct iommu_domain *domain;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020036
37 unsigned int refcount;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030038 spinlock_t iommu_lock; /* global for this whole object */
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020039
40 /*
41 * We don't change iopgd for a situation like pgd for a task,
42 * but share it globally for each iommu.
43 */
44 u32 *iopgd;
45 spinlock_t page_table_lock; /* protect iopgd */
46
47 int nr_tlb_entries;
48
49 struct list_head mmap;
50 struct mutex mmap_lock; /* protect mmap */
51
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020052 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
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030083 int (*enable)(struct omap_iommu *obj);
84 void (*disable)(struct omap_iommu *obj);
85 void (*set_twl)(struct omap_iommu *obj, bool on);
86 u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020087
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030088 void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
89 void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020090
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030091 struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
92 struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020093 int (*cr_valid)(struct cr_regs *cr);
94 u32 (*cr_to_virt)(struct cr_regs *cr);
95 void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030096 ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
97 char *buf);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020098
99 u32 (*get_pte_attr)(struct iotlb_entry *e);
100
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300101 void (*save_ctx)(struct omap_iommu *obj);
102 void (*restore_ctx)(struct omap_iommu *obj);
103 ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200104};
105
Paul Walmsley54864742012-09-23 17:28:23 -0600106/**
107 * struct omap_mmu_dev_attr - OMAP mmu device attributes for omap_hwmod
108 * @da_start: device address where the va space starts.
109 * @da_end: device address where the va space ends.
110 * @nr_tlb_entries: number of entries supported by the translation
111 * look-aside buffer (TLB).
112 */
113struct omap_mmu_dev_attr {
114 u32 da_start;
115 u32 da_end;
116 int nr_tlb_entries;
117};
118
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200119struct iommu_platform_data {
120 const char *name;
121 const char *clk_name;
122 const int nr_tlb_entries;
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +0000123 u32 da_start;
124 u32 da_end;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200125};
126
Ohad Ben-Cohen1fa02ac2011-09-23 16:37:27 +0300127/**
128 * struct iommu_arch_data - omap iommu private data
129 * @name: name of the iommu device
130 * @iommu_dev: handle of the iommu device
131 *
132 * This is an omap iommu private data object, which binds an iommu user
133 * to its iommu device. This object should be placed at the iommu user's
134 * dev_archdata so generic IOMMU API can be used without having to
135 * utilize omap-specific plumbing anymore.
136 */
137struct omap_iommu_arch_data {
138 const char *name;
139 struct omap_iommu *iommu_dev;
140};
141
Omar Ramirez Luna7460f142012-09-23 17:28:23 -0600142#ifdef CONFIG_IOMMU_API
Ohad Ben-Cohen1fa02ac2011-09-23 16:37:27 +0300143/**
144 * dev_to_omap_iommu() - retrieves an omap iommu object from a user device
145 * @dev: iommu client device
146 */
147static inline struct omap_iommu *dev_to_omap_iommu(struct device *dev)
148{
149 struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
150
151 return arch_data->iommu_dev;
152}
Omar Ramirez Luna7460f142012-09-23 17:28:23 -0600153#endif
Ohad Ben-Cohen1fa02ac2011-09-23 16:37:27 +0300154
David Cohend594f1f2011-02-16 19:35:51 +0000155/* IOMMU errors */
156#define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
157#define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
158#define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
159#define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
160#define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
161
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200162#if defined(CONFIG_ARCH_OMAP1)
163#error "iommu for this processor not implemented yet"
164#else
Tony Lindgrence491cf2009-10-20 09:40:47 -0700165#include <plat/iommu2.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200166#endif
167
168/*
169 * utilities for super page(16MB, 1MB, 64KB and 4KB)
170 */
171
172#define iopgsz_max(bytes) \
173 (((bytes) >= SZ_16M) ? SZ_16M : \
174 ((bytes) >= SZ_1M) ? SZ_1M : \
175 ((bytes) >= SZ_64K) ? SZ_64K : \
176 ((bytes) >= SZ_4K) ? SZ_4K : 0)
177
178#define bytes_to_iopgsz(bytes) \
179 (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
180 ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
181 ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
182 ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
183
184#define iopgsz_to_bytes(iopgsz) \
185 (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
186 ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
187 ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
188 ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
189
190#define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
191
192/*
193 * global functions
194 */
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300195extern u32 omap_iommu_arch_version(void);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200196
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300197extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200198
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300199extern int
200omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200201
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300202extern int omap_iommu_set_isr(const char *name,
203 int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
David Cohend594f1f2011-02-16 19:35:51 +0000204 void *priv),
205 void *isr_priv);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200206
Ohad Ben-Cohenfabdbca2011-10-11 00:18:33 +0200207extern void omap_iommu_save_ctx(struct device *dev);
208extern void omap_iommu_restore_ctx(struct device *dev);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200209
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300210extern int omap_install_iommu_arch(const struct iommu_functions *ops);
211extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200212
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300213extern int omap_foreach_iommu_device(void *data,
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200214 int (*fn)(struct device *, void *));
215
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300216extern ssize_t
217omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
218extern size_t
219omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200220
221#endif /* __MACH_IOMMU_H */