| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Contains routines needed to support swiotlb for ppc. | 
|  | 3 | * | 
| Kumar Gala | b8b14c6 | 2010-05-03 07:36:22 -0500 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. | 
|  | 5 | * Author: Becky Bruce | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 6 | * | 
|  | 7 | * This program is free software; you can redistribute  it and/or modify it | 
|  | 8 | * under  the terms of  the GNU General  Public License as published by the | 
|  | 9 | * Free Software Foundation;  either version 2 of the  License, or (at your | 
|  | 10 | * option) any later version. | 
|  | 11 | * | 
|  | 12 | */ | 
|  | 13 |  | 
|  | 14 | #include <linux/dma-mapping.h> | 
|  | 15 | #include <linux/pfn.h> | 
|  | 16 | #include <linux/of_platform.h> | 
|  | 17 | #include <linux/platform_device.h> | 
|  | 18 | #include <linux/pci.h> | 
|  | 19 |  | 
|  | 20 | #include <asm/machdep.h> | 
|  | 21 | #include <asm/swiotlb.h> | 
|  | 22 | #include <asm/dma.h> | 
|  | 23 | #include <asm/abs_addr.h> | 
|  | 24 |  | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 25 | unsigned int ppc_swiotlb_enable; | 
|  | 26 |  | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 27 | /* | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 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 | */ | 
| FUJITA Tomonori | 45223c5 | 2009-08-04 19:08:25 +0000 | [diff] [blame] | 34 | struct dma_map_ops swiotlb_dma_ops = { | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 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, | 
| FUJITA Tomonori | 712d3e2 | 2010-05-26 14:44:17 -0700 | [diff] [blame] | 42 | .sync_single_for_cpu = swiotlb_sync_single_for_cpu, | 
|  | 43 | .sync_single_for_device = swiotlb_sync_single_for_device, | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 44 | .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | 
| FUJITA Tomonori | 4a9a6bf | 2009-08-04 19:08:27 +0000 | [diff] [blame] | 45 | .sync_sg_for_device = swiotlb_sync_sg_for_device, | 
|  | 46 | .mapping_error = swiotlb_dma_mapping_error, | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 47 | }; | 
|  | 48 |  | 
| FUJITA Tomonori | 762afb7 | 2009-08-04 19:08:22 +0000 | [diff] [blame] | 49 | void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev) | 
|  | 50 | { | 
|  | 51 | struct pci_controller *hose; | 
|  | 52 | struct dev_archdata *sd; | 
|  | 53 |  | 
|  | 54 | hose = pci_bus_to_host(pdev->bus); | 
|  | 55 | sd = &pdev->dev.archdata; | 
|  | 56 | sd->max_direct_dma_addr = | 
|  | 57 | hose->dma_window_base_cur + hose->dma_window_size; | 
|  | 58 | } | 
|  | 59 |  | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 60 | static int ppc_swiotlb_bus_notify(struct notifier_block *nb, | 
|  | 61 | unsigned long action, void *data) | 
|  | 62 | { | 
|  | 63 | struct device *dev = data; | 
| FUJITA Tomonori | 762afb7 | 2009-08-04 19:08:22 +0000 | [diff] [blame] | 64 | struct dev_archdata *sd; | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 65 |  | 
|  | 66 | /* We are only intereted in device addition */ | 
|  | 67 | if (action != BUS_NOTIFY_ADD_DEVICE) | 
|  | 68 | return 0; | 
|  | 69 |  | 
| FUJITA Tomonori | 762afb7 | 2009-08-04 19:08:22 +0000 | [diff] [blame] | 70 | sd = &dev->archdata; | 
|  | 71 | sd->max_direct_dma_addr = 0; | 
|  | 72 |  | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 73 | /* May need to bounce if the device can't address all of DRAM */ | 
| Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 74 | if ((dma_get_mask(dev) + 1) < memblock_end_of_DRAM()) | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 75 | set_dma_ops(dev, &swiotlb_dma_ops); | 
|  | 76 |  | 
|  | 77 | return NOTIFY_DONE; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | static struct notifier_block ppc_swiotlb_plat_bus_notifier = { | 
|  | 81 | .notifier_call = ppc_swiotlb_bus_notify, | 
|  | 82 | .priority = 0, | 
|  | 83 | }; | 
|  | 84 |  | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 85 | int __init swiotlb_setup_bus_notifier(void) | 
|  | 86 | { | 
|  | 87 | bus_register_notifier(&platform_bus_type, | 
|  | 88 | &ppc_swiotlb_plat_bus_notifier); | 
| Becky Bruce | ec3cf2e | 2009-05-14 12:42:28 +0000 | [diff] [blame] | 89 | return 0; | 
|  | 90 | } |