blob: 7f1df0e18d514d5be617d8e986542ad6bbfd27ae [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;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020035
36 unsigned int refcount;
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +030037 spinlock_t iommu_lock; /* global for this whole object */
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020038
39 /*
40 * We don't change iopgd for a situation like pgd for a task,
41 * but share it globally for each iommu.
42 */
43 u32 *iopgd;
44 spinlock_t page_table_lock; /* protect iopgd */
45
46 int nr_tlb_entries;
47
48 struct list_head mmap;
49 struct mutex mmap_lock; /* protect mmap */
50
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030051 int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs, void *priv);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020052
53 void *ctx; /* iommu context: registres saved area */
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +000054 u32 da_start;
55 u32 da_end;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020056};
57
58struct cr_regs {
59 union {
60 struct {
61 u16 cam_l;
62 u16 cam_h;
63 };
64 u32 cam;
65 };
66 union {
67 struct {
68 u16 ram_l;
69 u16 ram_h;
70 };
71 u32 ram;
72 };
73};
74
75struct iotlb_lock {
76 short base;
77 short vict;
78};
79
80/* architecture specific functions */
81struct iommu_functions {
82 unsigned long version;
83
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030084 int (*enable)(struct omap_iommu *obj);
85 void (*disable)(struct omap_iommu *obj);
86 void (*set_twl)(struct omap_iommu *obj, bool on);
87 u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020088
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030089 void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
90 void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020091
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030092 struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
93 struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020094 int (*cr_valid)(struct cr_regs *cr);
95 u32 (*cr_to_virt)(struct cr_regs *cr);
96 void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +030097 ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
98 char *buf);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +020099
100 u32 (*get_pte_attr)(struct iotlb_entry *e);
101
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300102 void (*save_ctx)(struct omap_iommu *obj);
103 void (*restore_ctx)(struct omap_iommu *obj);
104 ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200105};
106
107struct iommu_platform_data {
108 const char *name;
109 const char *clk_name;
110 const int nr_tlb_entries;
Guzman Lugo, Fernandoc7f4ab22010-12-15 00:54:03 +0000111 u32 da_start;
112 u32 da_end;
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200113};
114
David Cohend594f1f2011-02-16 19:35:51 +0000115/* IOMMU errors */
116#define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
117#define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
118#define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
119#define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
120#define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
121
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200122#if defined(CONFIG_ARCH_OMAP1)
123#error "iommu for this processor not implemented yet"
124#else
Tony Lindgrence491cf2009-10-20 09:40:47 -0700125#include <plat/iommu2.h>
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200126#endif
127
128/*
129 * utilities for super page(16MB, 1MB, 64KB and 4KB)
130 */
131
132#define iopgsz_max(bytes) \
133 (((bytes) >= SZ_16M) ? SZ_16M : \
134 ((bytes) >= SZ_1M) ? SZ_1M : \
135 ((bytes) >= SZ_64K) ? SZ_64K : \
136 ((bytes) >= SZ_4K) ? SZ_4K : 0)
137
138#define bytes_to_iopgsz(bytes) \
139 (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
140 ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
141 ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
142 ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
143
144#define iopgsz_to_bytes(iopgsz) \
145 (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
146 ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
147 ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
148 ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
149
150#define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
151
152/*
153 * global functions
154 */
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300155extern u32 omap_iommu_arch_version(void);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200156
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300157extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200158
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300159extern int
160omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200161
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300162extern int omap_iommu_set_isr(const char *name,
163 int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
David Cohend594f1f2011-02-16 19:35:51 +0000164 void *priv),
165 void *isr_priv);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200166
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300167extern void omap_iommu_save_ctx(struct omap_iommu *obj);
168extern void omap_iommu_restore_ctx(struct omap_iommu *obj);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200169
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300170extern int omap_install_iommu_arch(const struct iommu_functions *ops);
171extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200172
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300173extern int omap_foreach_iommu_device(void *data,
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200174 int (*fn)(struct device *, void *));
175
Ohad Ben-Cohen6c32df42011-08-17 22:57:56 +0300176extern ssize_t
177omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
178extern size_t
179omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
Ohad Ben-Cohenf626b522011-06-02 01:46:12 +0300180struct device *omap_find_iommu_device(const char *name);
Hiroshi DOYUa9dcad52009-01-26 15:13:40 +0200181
182#endif /* __MACH_IOMMU_H */