diff options
Diffstat (limited to 'arch/powerpc/kernel/dma-swiotlb.c')
-rw-r--r-- | arch/powerpc/kernel/dma-swiotlb.c | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c index e8a57de85bcf..e96cbbd9b449 100644 --- a/arch/powerpc/kernel/dma-swiotlb.c +++ b/arch/powerpc/kernel/dma-swiotlb.c | |||
@@ -25,33 +25,13 @@ int swiotlb __read_mostly; | |||
25 | unsigned int ppc_swiotlb_enable; | 25 | unsigned int ppc_swiotlb_enable; |
26 | 26 | ||
27 | /* | 27 | /* |
28 | * Determine if an address is reachable by a pci device, or if we must bounce. | ||
29 | */ | ||
30 | static int | ||
31 | swiotlb_pci_addr_needs_map(struct device *hwdev, dma_addr_t addr, size_t size) | ||
32 | { | ||
33 | dma_addr_t max; | ||
34 | struct pci_controller *hose; | ||
35 | struct pci_dev *pdev = to_pci_dev(hwdev); | ||
36 | |||
37 | hose = pci_bus_to_host(pdev->bus); | ||
38 | max = hose->dma_window_base_cur + hose->dma_window_size; | ||
39 | |||
40 | /* check that we're within mapped pci window space */ | ||
41 | if ((addr + size > max) | (addr < hose->dma_window_base_cur)) | ||
42 | return 1; | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | * At the moment, all platforms that use this code only require | 28 | * At the moment, all platforms that use this code only require |
49 | * swiotlb to be used if we're operating on HIGHMEM. Since | 29 | * swiotlb to be used if we're operating on HIGHMEM. Since |
50 | * we don't ever call anything other than map_sg, unmap_sg, | 30 | * we don't ever call anything other than map_sg, unmap_sg, |
51 | * map_page, and unmap_page on highmem, use normal dma_ops | 31 | * map_page, and unmap_page on highmem, use normal dma_ops |
52 | * for everything else. | 32 | * for everything else. |
53 | */ | 33 | */ |
54 | struct dma_mapping_ops swiotlb_dma_ops = { | 34 | struct dma_map_ops swiotlb_dma_ops = { |
55 | .alloc_coherent = dma_direct_alloc_coherent, | 35 | .alloc_coherent = dma_direct_alloc_coherent, |
56 | .free_coherent = dma_direct_free_coherent, | 36 | .free_coherent = dma_direct_free_coherent, |
57 | .map_sg = swiotlb_map_sg_attrs, | 37 | .map_sg = swiotlb_map_sg_attrs, |
@@ -62,33 +42,34 @@ struct dma_mapping_ops swiotlb_dma_ops = { | |||
62 | .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu, | 42 | .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu, |
63 | .sync_single_range_for_device = swiotlb_sync_single_range_for_device, | 43 | .sync_single_range_for_device = swiotlb_sync_single_range_for_device, |
64 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | 44 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, |
65 | .sync_sg_for_device = swiotlb_sync_sg_for_device | 45 | .sync_sg_for_device = swiotlb_sync_sg_for_device, |
46 | .mapping_error = swiotlb_dma_mapping_error, | ||
66 | }; | 47 | }; |
67 | 48 | ||
68 | struct dma_mapping_ops swiotlb_pci_dma_ops = { | 49 | void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev) |
69 | .alloc_coherent = dma_direct_alloc_coherent, | 50 | { |
70 | .free_coherent = dma_direct_free_coherent, | 51 | struct pci_controller *hose; |
71 | .map_sg = swiotlb_map_sg_attrs, | 52 | struct dev_archdata *sd; |
72 | .unmap_sg = swiotlb_unmap_sg_attrs, | 53 | |
73 | .dma_supported = swiotlb_dma_supported, | 54 | hose = pci_bus_to_host(pdev->bus); |
74 | .map_page = swiotlb_map_page, | 55 | sd = &pdev->dev.archdata; |
75 | .unmap_page = swiotlb_unmap_page, | 56 | sd->max_direct_dma_addr = |
76 | .addr_needs_map = swiotlb_pci_addr_needs_map, | 57 | hose->dma_window_base_cur + hose->dma_window_size; |
77 | .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu, | 58 | } |
78 | .sync_single_range_for_device = swiotlb_sync_single_range_for_device, | ||
79 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | ||
80 | .sync_sg_for_device = swiotlb_sync_sg_for_device | ||
81 | }; | ||
82 | 59 | ||
83 | static int ppc_swiotlb_bus_notify(struct notifier_block *nb, | 60 | static int ppc_swiotlb_bus_notify(struct notifier_block *nb, |
84 | unsigned long action, void *data) | 61 | unsigned long action, void *data) |
85 | { | 62 | { |
86 | struct device *dev = data; | 63 | struct device *dev = data; |
64 | struct dev_archdata *sd; | ||
87 | 65 | ||
88 | /* We are only intereted in device addition */ | 66 | /* We are only intereted in device addition */ |
89 | if (action != BUS_NOTIFY_ADD_DEVICE) | 67 | if (action != BUS_NOTIFY_ADD_DEVICE) |
90 | return 0; | 68 | return 0; |
91 | 69 | ||
70 | sd = &dev->archdata; | ||
71 | sd->max_direct_dma_addr = 0; | ||
72 | |||
92 | /* May need to bounce if the device can't address all of DRAM */ | 73 | /* May need to bounce if the device can't address all of DRAM */ |
93 | if (dma_get_mask(dev) < lmb_end_of_DRAM()) | 74 | if (dma_get_mask(dev) < lmb_end_of_DRAM()) |
94 | set_dma_ops(dev, &swiotlb_dma_ops); | 75 | set_dma_ops(dev, &swiotlb_dma_ops); |