powerpc: Remove addr_needs_map in struct dma_mapping_ops
[deliverable/linux.git] / arch / powerpc / kernel / dma-swiotlb.c
1 /*
2 * Contains routines needed to support swiotlb for ppc.
3 *
4 * Copyright (C) 2009 Becky Bruce, Freescale Semiconductor
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13 #include <linux/dma-mapping.h>
14 #include <linux/pfn.h>
15 #include <linux/of_platform.h>
16 #include <linux/platform_device.h>
17 #include <linux/pci.h>
18
19 #include <asm/machdep.h>
20 #include <asm/swiotlb.h>
21 #include <asm/dma.h>
22 #include <asm/abs_addr.h>
23
24 int swiotlb __read_mostly;
25 unsigned int ppc_swiotlb_enable;
26
27 /*
28 * At the moment, all platforms that use this code only require
29 * swiotlb to be used if we're operating on HIGHMEM. Since
30 * we don't ever call anything other than map_sg, unmap_sg,
31 * map_page, and unmap_page on highmem, use normal dma_ops
32 * for everything else.
33 */
34 struct dma_mapping_ops swiotlb_dma_ops = {
35 .alloc_coherent = dma_direct_alloc_coherent,
36 .free_coherent = dma_direct_free_coherent,
37 .map_sg = swiotlb_map_sg_attrs,
38 .unmap_sg = swiotlb_unmap_sg_attrs,
39 .dma_supported = swiotlb_dma_supported,
40 .map_page = swiotlb_map_page,
41 .unmap_page = swiotlb_unmap_page,
42 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
43 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
44 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
45 .sync_sg_for_device = swiotlb_sync_sg_for_device
46 };
47
48 struct dma_mapping_ops swiotlb_pci_dma_ops = {
49 .alloc_coherent = dma_direct_alloc_coherent,
50 .free_coherent = dma_direct_free_coherent,
51 .map_sg = swiotlb_map_sg_attrs,
52 .unmap_sg = swiotlb_unmap_sg_attrs,
53 .dma_supported = swiotlb_dma_supported,
54 .map_page = swiotlb_map_page,
55 .unmap_page = swiotlb_unmap_page,
56 .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
57 .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
58 .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
59 .sync_sg_for_device = swiotlb_sync_sg_for_device
60 };
61
62 void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
63 {
64 struct pci_controller *hose;
65 struct dev_archdata *sd;
66
67 hose = pci_bus_to_host(pdev->bus);
68 sd = &pdev->dev.archdata;
69 sd->max_direct_dma_addr =
70 hose->dma_window_base_cur + hose->dma_window_size;
71 }
72
73 static int ppc_swiotlb_bus_notify(struct notifier_block *nb,
74 unsigned long action, void *data)
75 {
76 struct device *dev = data;
77 struct dev_archdata *sd;
78
79 /* We are only intereted in device addition */
80 if (action != BUS_NOTIFY_ADD_DEVICE)
81 return 0;
82
83 sd = &dev->archdata;
84 sd->max_direct_dma_addr = 0;
85
86 /* May need to bounce if the device can't address all of DRAM */
87 if (dma_get_mask(dev) < lmb_end_of_DRAM())
88 set_dma_ops(dev, &swiotlb_dma_ops);
89
90 return NOTIFY_DONE;
91 }
92
93 static struct notifier_block ppc_swiotlb_plat_bus_notifier = {
94 .notifier_call = ppc_swiotlb_bus_notify,
95 .priority = 0,
96 };
97
98 static struct notifier_block ppc_swiotlb_of_bus_notifier = {
99 .notifier_call = ppc_swiotlb_bus_notify,
100 .priority = 0,
101 };
102
103 int __init swiotlb_setup_bus_notifier(void)
104 {
105 bus_register_notifier(&platform_bus_type,
106 &ppc_swiotlb_plat_bus_notifier);
107 bus_register_notifier(&of_platform_bus_type,
108 &ppc_swiotlb_of_bus_notifier);
109
110 return 0;
111 }
This page took 0.070944 seconds and 5 git commands to generate.