diff options
author | Ishizaki Kou <kou.ishizaki@toshiba.co.jp> | 2007-02-02 02:39:34 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-02-06 22:03:21 -0500 |
commit | 97a9b58409403baf7a8b0ccbd3d27993790dcdab (patch) | |
tree | 1ea34c4a865bb1015f09561363c0c6d9957ad87a /arch/powerpc | |
parent | 7163c7c9d266862ad9a0a0203d204113034cb5fb (diff) |
[POWERPC] Celleb: support iommu
This patch creates Celleb platform dependent file to support iommu.
Signed-off-by: Kou Ishizaki <kou.ishizaki@toshiba.co.jp>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/platforms/celleb/iommu.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/celleb/iommu.c b/arch/powerpc/platforms/celleb/iommu.c new file mode 100644 index 000000000000..f63b94c65353 --- /dev/null +++ b/arch/powerpc/platforms/celleb/iommu.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * Support for IOMMU on Celleb platform. | ||
3 | * | ||
4 | * (C) Copyright 2006-2007 TOSHIBA 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 along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/dma-mapping.h> | ||
24 | #include <linux/pci.h> | ||
25 | |||
26 | #include <asm/of_platform.h> | ||
27 | |||
28 | #include "beat_wrapper.h" | ||
29 | |||
30 | #define DMA_FLAGS 0xf800000000000000UL /* r/w permitted, coherency required, | ||
31 | strongest order */ | ||
32 | |||
33 | static int __init find_dma_window(u64 *io_space_id, u64 *ioid, | ||
34 | u64 *base, u64 *size, u64 *io_page_size) | ||
35 | { | ||
36 | struct device_node *dn; | ||
37 | const unsigned long *dma_window; | ||
38 | |||
39 | for_each_node_by_type(dn, "ioif") { | ||
40 | dma_window = get_property(dn, "toshiba,dma-window", NULL); | ||
41 | if (dma_window) { | ||
42 | *io_space_id = (dma_window[0] >> 32) & 0xffffffffUL; | ||
43 | *ioid = dma_window[0] & 0x7ffUL; | ||
44 | *base = dma_window[1]; | ||
45 | *size = dma_window[2]; | ||
46 | *io_page_size = 1 << dma_window[3]; | ||
47 | of_node_put(dn); | ||
48 | return 1; | ||
49 | } | ||
50 | } | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static void __init celleb_init_direct_mapping(void) | ||
55 | { | ||
56 | u64 lpar_addr, io_addr; | ||
57 | u64 io_space_id, ioid, dma_base, dma_size, io_page_size; | ||
58 | |||
59 | if (!find_dma_window(&io_space_id, &ioid, &dma_base, &dma_size, | ||
60 | &io_page_size)) { | ||
61 | pr_info("No dma window found !\n"); | ||
62 | return; | ||
63 | } | ||
64 | |||
65 | for (lpar_addr = 0; lpar_addr < dma_size; lpar_addr += io_page_size) { | ||
66 | io_addr = lpar_addr + dma_base; | ||
67 | (void)beat_put_iopte(io_space_id, io_addr, lpar_addr, | ||
68 | ioid, DMA_FLAGS); | ||
69 | } | ||
70 | |||
71 | dma_direct_offset = dma_base; | ||
72 | } | ||
73 | |||
74 | static int celleb_of_bus_notify(struct notifier_block *nb, | ||
75 | unsigned long action, void *data) | ||
76 | { | ||
77 | struct device *dev = data; | ||
78 | |||
79 | /* We are only intereted in device addition */ | ||
80 | if (action != BUS_NOTIFY_ADD_DEVICE) | ||
81 | return 0; | ||
82 | |||
83 | dev->archdata.dma_ops = pci_dma_ops; | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static struct notifier_block celleb_of_bus_notifier = { | ||
89 | .notifier_call = celleb_of_bus_notify | ||
90 | }; | ||
91 | |||
92 | static int __init celleb_init_iommu(void) | ||
93 | { | ||
94 | if (!machine_is(celleb)) | ||
95 | return -ENODEV; | ||
96 | |||
97 | celleb_init_direct_mapping(); | ||
98 | pci_dma_ops = &dma_direct_ops; | ||
99 | bus_register_notifier(&of_platform_bus_type, &celleb_of_bus_notifier); | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | arch_initcall(celleb_init_iommu); | ||