2 * Support for IOMMU on Celleb platform.
4 * (C) Copyright 2006-2007 TOSHIBA CORPORATION
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.
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.
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.
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/pci.h>
25 #include <linux/of_platform.h>
27 #include <asm/firmware.h>
29 #include "beat_wrapper.h"
31 #define DMA_FLAGS 0xf800000000000000UL /* r/w permitted, coherency required,
34 static int __init
find_dma_window(u64
*io_space_id
, u64
*ioid
,
35 u64
*base
, u64
*size
, u64
*io_page_size
)
37 struct device_node
*dn
;
38 const unsigned long *dma_window
;
40 for_each_node_by_type(dn
, "ioif") {
41 dma_window
= of_get_property(dn
, "toshiba,dma-window", NULL
);
43 *io_space_id
= (dma_window
[0] >> 32) & 0xffffffffUL
;
44 *ioid
= dma_window
[0] & 0x7ffUL
;
45 *base
= dma_window
[1];
46 *size
= dma_window
[2];
47 *io_page_size
= 1 << dma_window
[3];
55 static void __init
celleb_init_direct_mapping(void)
57 u64 lpar_addr
, io_addr
;
58 u64 io_space_id
, ioid
, dma_base
, dma_size
, io_page_size
;
60 if (!find_dma_window(&io_space_id
, &ioid
, &dma_base
, &dma_size
,
62 pr_info("No dma window found !\n");
66 for (lpar_addr
= 0; lpar_addr
< dma_size
; lpar_addr
+= io_page_size
) {
67 io_addr
= lpar_addr
+ dma_base
;
68 (void)beat_put_iopte(io_space_id
, io_addr
, lpar_addr
,
72 dma_direct_offset
= dma_base
;
75 static int celleb_of_bus_notify(struct notifier_block
*nb
,
76 unsigned long action
, void *data
)
78 struct device
*dev
= data
;
80 /* We are only intereted in device addition */
81 if (action
!= BUS_NOTIFY_ADD_DEVICE
)
84 dev
->archdata
.dma_ops
= get_pci_dma_ops();
89 static struct notifier_block celleb_of_bus_notifier
= {
90 .notifier_call
= celleb_of_bus_notify
93 static int __init
celleb_init_iommu(void)
95 if (!firmware_has_feature(FW_FEATURE_BEAT
))
98 celleb_init_direct_mapping();
99 set_pci_dma_ops(&dma_direct_ops
);
100 bus_register_notifier(&of_platform_bus_type
, &celleb_of_bus_notifier
);
105 arch_initcall(celleb_init_iommu
);