hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/powerpc/include/asm/iommu.h
....@@ -1,21 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
34 * Rewrite, cleanup:
45 * Copyright (C) 2004 Olof Johansson <olof@lixom.net>, IBM Corporation
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
196 */
207
218 #ifndef _ASM_IOMMU_H
....@@ -25,7 +12,7 @@
2512 #include <linux/compiler.h>
2613 #include <linux/spinlock.h>
2714 #include <linux/device.h>
28
-#include <linux/dma-mapping.h>
15
+#include <linux/dma-map-ops.h>
2916 #include <linux/bitops.h>
3017 #include <asm/machdep.h>
3118 #include <asm/types.h>
....@@ -35,11 +22,11 @@
3522 #define IOMMU_PAGE_SHIFT_4K 12
3623 #define IOMMU_PAGE_SIZE_4K (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K)
3724 #define IOMMU_PAGE_MASK_4K (~((1 << IOMMU_PAGE_SHIFT_4K) - 1))
38
-#define IOMMU_PAGE_ALIGN_4K(addr) _ALIGN_UP(addr, IOMMU_PAGE_SIZE_4K)
25
+#define IOMMU_PAGE_ALIGN_4K(addr) ALIGN(addr, IOMMU_PAGE_SIZE_4K)
3926
4027 #define IOMMU_PAGE_SIZE(tblptr) (ASM_CONST(1) << (tblptr)->it_page_shift)
4128 #define IOMMU_PAGE_MASK(tblptr) (~((1 << (tblptr)->it_page_shift) - 1))
42
-#define IOMMU_PAGE_ALIGN(addr, tblptr) _ALIGN_UP(addr, IOMMU_PAGE_SIZE(tblptr))
29
+#define IOMMU_PAGE_ALIGN(addr, tblptr) ALIGN(addr, IOMMU_PAGE_SIZE(tblptr))
4330
4431 /* Boot time flags */
4532 extern int iommu_is_off;
....@@ -61,15 +48,16 @@
6148 * returns old TCE and DMA direction mask.
6249 * @tce is a physical address.
6350 */
64
- int (*exchange)(struct iommu_table *tbl,
51
+ int (*xchg_no_kill)(struct iommu_table *tbl,
6552 long index,
6653 unsigned long *hpa,
67
- enum dma_data_direction *direction);
68
- /* Real mode */
69
- int (*exchange_rm)(struct iommu_table *tbl,
70
- long index,
71
- unsigned long *hpa,
72
- enum dma_data_direction *direction);
54
+ enum dma_data_direction *direction,
55
+ bool realmode);
56
+
57
+ void (*tce_kill)(struct iommu_table *tbl,
58
+ unsigned long index,
59
+ unsigned long pages,
60
+ bool realmode);
7361
7462 __be64 *(*useraddrptr)(struct iommu_table *tbl, long index, bool alloc);
7563 #endif
....@@ -124,9 +112,11 @@
124112 struct iommu_table_ops *it_ops;
125113 struct kref it_kref;
126114 int it_nid;
115
+ unsigned long it_reserved_start; /* Start of not-DMA-able (MMIO) area */
116
+ unsigned long it_reserved_end;
127117 };
128118
129
-#define IOMMU_TABLE_USERSPACE_ENTRY_RM(tbl, entry) \
119
+#define IOMMU_TABLE_USERSPACE_ENTRY_RO(tbl, entry) \
130120 ((tbl)->it_ops->useraddrptr((tbl), (entry), false))
131121 #define IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry) \
132122 ((tbl)->it_ops->useraddrptr((tbl), (entry), true))
....@@ -142,8 +132,6 @@
142132 struct scatterlist;
143133
144134 #ifdef CONFIG_PPC64
145
-
146
-#define IOMMU_MAPPING_ERROR (~(dma_addr_t)0x0)
147135
148136 static inline void set_iommu_table_base(struct device *dev,
149137 struct iommu_table *base)
....@@ -164,8 +152,9 @@
164152 /* Initializes an iommu_table based in values set in the passed-in
165153 * structure
166154 */
167
-extern struct iommu_table *iommu_init_table(struct iommu_table * tbl,
168
- int nid);
155
+extern struct iommu_table *iommu_init_table(struct iommu_table *tbl,
156
+ int nid, unsigned long res_start, unsigned long res_end);
157
+
169158 #define IOMMU_TABLE_GROUP_MAX_TABLES 2
170159
171160 struct iommu_table_group;
....@@ -215,11 +204,18 @@
215204
216205 extern void iommu_register_group(struct iommu_table_group *table_group,
217206 int pci_domain_number, unsigned long pe_num);
218
-extern int iommu_add_device(struct device *dev);
207
+extern int iommu_add_device(struct iommu_table_group *table_group,
208
+ struct device *dev);
219209 extern void iommu_del_device(struct device *dev);
220
-extern int __init tce_iommu_bus_notifier_init(void);
221
-extern long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
222
- unsigned long *hpa, enum dma_data_direction *direction);
210
+extern long iommu_tce_xchg(struct mm_struct *mm, struct iommu_table *tbl,
211
+ unsigned long entry, unsigned long *hpa,
212
+ enum dma_data_direction *direction);
213
+extern long iommu_tce_xchg_no_kill(struct mm_struct *mm,
214
+ struct iommu_table *tbl,
215
+ unsigned long entry, unsigned long *hpa,
216
+ enum dma_data_direction *direction);
217
+extern void iommu_tce_kill(struct iommu_table *tbl,
218
+ unsigned long entry, unsigned long pages);
223219 #else
224220 static inline void iommu_register_group(struct iommu_table_group *table_group,
225221 int pci_domain_number,
....@@ -227,7 +223,8 @@
227223 {
228224 }
229225
230
-static inline int iommu_add_device(struct device *dev)
226
+static inline int iommu_add_device(struct iommu_table_group *table_group,
227
+ struct device *dev)
231228 {
232229 return 0;
233230 }
....@@ -235,15 +232,9 @@
235232 static inline void iommu_del_device(struct device *dev)
236233 {
237234 }
238
-
239
-static inline int __init tce_iommu_bus_notifier_init(void)
240
-{
241
- return 0;
242
-}
243235 #endif /* !CONFIG_IOMMU_API */
244236
245
-int dma_iommu_mapping_error(struct device *dev, dma_addr_t dma_addr);
246
-
237
+u64 dma_iommu_get_required_mask(struct device *dev);
247238 #else
248239
249240 static inline void *get_iommu_table_base(struct device *dev)
....@@ -325,5 +316,13 @@
325316 extern enum dma_data_direction iommu_tce_direction(unsigned long tce);
326317 extern unsigned long iommu_direction_to_tce_perm(enum dma_data_direction dir);
327318
319
+#ifdef CONFIG_PPC_CELL_NATIVE
320
+extern bool iommu_fixed_is_weak;
321
+#else
322
+#define iommu_fixed_is_weak false
323
+#endif
324
+
325
+extern const struct dma_map_ops dma_iommu_ops;
326
+
328327 #endif /* __KERNEL__ */
329328 #endif /* _ASM_IOMMU_H */