Path: blob/master/arch/powerpc/platforms/cell/beat_iommu.c
10818 views
/*1* Support for IOMMU on Celleb platform.2*3* (C) Copyright 2006-2007 TOSHIBA CORPORATION4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License along16* with this program; if not, write to the Free Software Foundation, Inc.,17* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.18*/1920#include <linux/kernel.h>21#include <linux/init.h>22#include <linux/dma-mapping.h>23#include <linux/pci.h>24#include <linux/of_platform.h>2526#include <asm/machdep.h>2728#include "beat_wrapper.h"2930#define DMA_FLAGS 0xf800000000000000UL /* r/w permitted, coherency required,31strongest order */3233static int __init find_dma_window(u64 *io_space_id, u64 *ioid,34u64 *base, u64 *size, u64 *io_page_size)35{36struct device_node *dn;37const unsigned long *dma_window;3839for_each_node_by_type(dn, "ioif") {40dma_window = of_get_property(dn, "toshiba,dma-window", NULL);41if (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];47of_node_put(dn);48return 1;49}50}51return 0;52}5354static unsigned long celleb_dma_direct_offset;5556static void __init celleb_init_direct_mapping(void)57{58u64 lpar_addr, io_addr;59u64 io_space_id, ioid, dma_base, dma_size, io_page_size;6061if (!find_dma_window(&io_space_id, &ioid, &dma_base, &dma_size,62&io_page_size)) {63pr_info("No dma window found !\n");64return;65}6667for (lpar_addr = 0; lpar_addr < dma_size; lpar_addr += io_page_size) {68io_addr = lpar_addr + dma_base;69(void)beat_put_iopte(io_space_id, io_addr, lpar_addr,70ioid, DMA_FLAGS);71}7273celleb_dma_direct_offset = dma_base;74}7576static void celleb_dma_dev_setup(struct device *dev)77{78set_dma_ops(dev, &dma_direct_ops);79set_dma_offset(dev, celleb_dma_direct_offset);80}8182static void celleb_pci_dma_dev_setup(struct pci_dev *pdev)83{84celleb_dma_dev_setup(&pdev->dev);85}8687static int celleb_of_bus_notify(struct notifier_block *nb,88unsigned long action, void *data)89{90struct device *dev = data;9192/* We are only intereted in device addition */93if (action != BUS_NOTIFY_ADD_DEVICE)94return 0;9596celleb_dma_dev_setup(dev);9798return 0;99}100101static struct notifier_block celleb_of_bus_notifier = {102.notifier_call = celleb_of_bus_notify103};104105static int __init celleb_init_iommu(void)106{107celleb_init_direct_mapping();108ppc_md.pci_dma_dev_setup = celleb_pci_dma_dev_setup;109bus_register_notifier(&platform_bus_type, &celleb_of_bus_notifier);110111return 0;112}113114machine_arch_initcall(celleb_beat, celleb_init_iommu);115116117