[PATCH] cell: cleanup iommu initialization
Christoph Hellwig
hch at lst.de
Thu Mar 9 02:49:46 EST 2006
- add a cell_map_one_iommu helper to factor out some duplicated code
- use for_each_node_by_type from my last patch
- add ul postfix to some large constants in the hardcoded case to fix
up sparse warnings.
- minor formatting fixes.
Note that the hardcoded case still doesn't look very nice. The
hardcoded addresses should probably get some meaningull defines,
and mapping both iommus into the same dma window looks at least slightly
odd to me.
Signed-off-by: Christoph Hellwig <hch at lst.de>
Index: linux-2.6/arch/powerpc/platforms/cell/iommu.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/iommu.c 2006-03-08 16:39:56.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/iommu.c 2006-03-08 16:45:13.000000000 +0100
@@ -335,67 +335,56 @@
iommu_devnode_setup(d);
}
-
-static int cell_map_iommu_hardcoded(int num_nodes)
+static void cell_map_one_iommu(struct cell_iommu *iommu,
+ unsigned long base, unsigned long mmio_base)
{
- struct cell_iommu *iommu = NULL;
-
- pr_debug("%s(%d): Using hardcoded defaults\n", __FUNCTION__, __LINE__);
+ iommu->base = base;
+ iommu->mmio_base = mmio_base;
- /* node 0 */
- iommu = &cell_iommus[0];
- iommu->mapped_base = __ioremap(0x20000511000, 0x1000, _PAGE_NO_CACHE);
- iommu->mapped_mmio_base = __ioremap(0x20000510000, 0x1000, _PAGE_NO_CACHE);
+ iommu->mapped_base = __ioremap(base, 0x1000, _PAGE_NO_CACHE);
+ iommu->mapped_mmio_base = __ioremap(mmio_base, 0x1000, _PAGE_NO_CACHE);
enable_mapping(iommu->mapped_base, iommu->mapped_mmio_base);
+}
- cell_do_map_iommu(iommu, 0x048a,
- 0x20000000ul,0x20000000ul);
-
- if (num_nodes < 2)
- return 0;
-
- /* node 1 */
- iommu = &cell_iommus[1];
- iommu->mapped_base = __ioremap(0x30000511000, 0x1000, _PAGE_NO_CACHE);
- iommu->mapped_mmio_base = __ioremap(0x30000510000, 0x1000, _PAGE_NO_CACHE);
-
- enable_mapping(iommu->mapped_base, iommu->mapped_mmio_base);
+static int cell_map_iommu_hardcoded(int num_nodes)
+{
+ pr_debug("%s(%d): Using hardcoded defaults\n", __FUNCTION__, __LINE__);
- cell_do_map_iommu(iommu, 0x048a,
- 0x20000000,0x20000000ul);
+ /* node 0 */
+ cell_map_one_iommu(&cell_iommus[0], 0x20000511000ul, 0x20000510000ul);
+ cell_do_map_iommu(&cell_iommus[0], 0x048a, 0x20000000ul, 0x20000000ul);
+ if (num_nodes > 1) {
+ /* node 1 */
+ cell_map_one_iommu(&cell_iommus[1], 0x30000511000ul, 0x30000510000ul);
+ cell_do_map_iommu(&cell_iommus[1], 0x048a, 0x20000000ul, 0x20000000ul);
+ }
return 0;
}
-
static int cell_map_iommu(void)
{
unsigned int num_nodes = 0, *node_id;
unsigned long *base, *mmio_base;
struct device_node *dn;
- struct cell_iommu *iommu = NULL;
/* determine number of nodes (=iommus) */
pr_debug("%s(%d): determining number of nodes...", __FUNCTION__, __LINE__);
- for(dn = of_find_node_by_type(NULL, "cpu");
- dn;
- dn = of_find_node_by_type(dn, "cpu")) {
- node_id = (unsigned int *)get_property(dn, "node-id", NULL);
+ for_each_node_by_type(dn, "cpu") {
+ node_id = (unsigned int *)get_property(dn, "node-id", NULL);
if (num_nodes < *node_id)
num_nodes = *node_id;
- }
+ }
num_nodes++;
pr_debug("%i found.\n", num_nodes);
/* map the iommu registers for each node */
pr_debug("%s(%d): Looping through nodes\n", __FUNCTION__, __LINE__);
- for(dn = of_find_node_by_type(NULL, "cpu");
- dn;
- dn = of_find_node_by_type(dn, "cpu")) {
+ for_each_node_by_type(dn, "cpu") {
node_id = (unsigned int *)get_property(dn, "node-id", NULL);
base = (unsigned long *)get_property(dn, "ioc-cache", NULL);
mmio_base = (unsigned long *)get_property(dn, "ioc-translation", NULL);
@@ -403,16 +392,7 @@
if (!base || !mmio_base || !node_id)
return cell_map_iommu_hardcoded(num_nodes);
- iommu = &cell_iommus[*node_id];
- iommu->base = *base;
- iommu->mmio_base = *mmio_base;
-
- iommu->mapped_base = __ioremap(*base, 0x1000, _PAGE_NO_CACHE);
- iommu->mapped_mmio_base = __ioremap(*mmio_base, 0x1000, _PAGE_NO_CACHE);
-
- enable_mapping(iommu->mapped_base,
- iommu->mapped_mmio_base);
-
+ cell_map_one_iommu(&cell_iommus[*node_id], *base, *mmio_base);
/* everything else will be done in iommu_bus_setup */
}
More information about the Linuxppc64-dev
mailing list