Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 1 | /* Glue code to lib/swiotlb-xen.c */ |
| 2 | |
| 3 | #include <linux/dma-mapping.h> |
Konrad Rzeszutek Wilk | 74226b8 | 2010-08-19 13:34:58 -0400 | [diff] [blame] | 4 | #include <linux/pci.h> |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 5 | #include <xen/swiotlb-xen.h> |
| 6 | |
| 7 | #include <asm/xen/hypervisor.h> |
| 8 | #include <xen/xen.h> |
Konrad Rzeszutek Wilk | 5cb3a26 | 2010-08-26 13:58:01 -0400 | [diff] [blame] | 9 | #include <asm/iommu_table.h> |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 10 | |
| 11 | int xen_swiotlb __read_mostly; |
| 12 | |
| 13 | static struct dma_map_ops xen_swiotlb_dma_ops = { |
| 14 | .mapping_error = xen_swiotlb_dma_mapping_error, |
Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 15 | .alloc = xen_swiotlb_alloc_coherent, |
| 16 | .free = xen_swiotlb_free_coherent, |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 17 | .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu, |
| 18 | .sync_single_for_device = xen_swiotlb_sync_single_for_device, |
| 19 | .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, |
| 20 | .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, |
| 21 | .map_sg = xen_swiotlb_map_sg_attrs, |
| 22 | .unmap_sg = xen_swiotlb_unmap_sg_attrs, |
| 23 | .map_page = xen_swiotlb_map_page, |
| 24 | .unmap_page = xen_swiotlb_unmap_page, |
| 25 | .dma_supported = xen_swiotlb_dma_supported, |
| 26 | }; |
| 27 | |
| 28 | /* |
| 29 | * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary |
| 30 | * |
| 31 | * This returns non-zero if we are forced to use xen_swiotlb (by the boot |
| 32 | * option). |
| 33 | */ |
| 34 | int __init pci_xen_swiotlb_detect(void) |
| 35 | { |
| 36 | |
Konrad Rzeszutek Wilk | 988f0e2 | 2012-07-27 20:10:58 -0400 | [diff] [blame^] | 37 | if (!xen_pv_domain()) |
| 38 | return 0; |
| 39 | |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 40 | /* If running as PV guest, either iommu=soft, or swiotlb=force will |
| 41 | * activate this IOMMU. If running as PV privileged, activate it |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 42 | * irregardless. |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 43 | */ |
Konrad Rzeszutek Wilk | 988f0e2 | 2012-07-27 20:10:58 -0400 | [diff] [blame^] | 44 | if ((xen_initial_domain() || swiotlb || swiotlb_force)) |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 45 | xen_swiotlb = 1; |
| 46 | |
| 47 | /* If we are running under Xen, we MUST disable the native SWIOTLB. |
| 48 | * Don't worry about swiotlb_force flag activating the native, as |
| 49 | * the 'swiotlb' flag is the only one turning it on. */ |
Konrad Rzeszutek Wilk | 988f0e2 | 2012-07-27 20:10:58 -0400 | [diff] [blame^] | 50 | swiotlb = 0; |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 51 | |
| 52 | return xen_swiotlb; |
| 53 | } |
| 54 | |
| 55 | void __init pci_xen_swiotlb_init(void) |
| 56 | { |
| 57 | if (xen_swiotlb) { |
| 58 | xen_swiotlb_init(1); |
| 59 | dma_ops = &xen_swiotlb_dma_ops; |
Konrad Rzeszutek Wilk | 74226b8 | 2010-08-19 13:34:58 -0400 | [diff] [blame] | 60 | |
| 61 | /* Make sure ACS will be enabled */ |
| 62 | pci_request_acs(); |
Konrad Rzeszutek Wilk | bbbe573 | 2010-02-09 14:30:55 -0500 | [diff] [blame] | 63 | } |
| 64 | } |
Konrad Rzeszutek Wilk | 5cb3a26 | 2010-08-26 13:58:01 -0400 | [diff] [blame] | 65 | IOMMU_INIT_FINISH(pci_xen_swiotlb_detect, |
| 66 | 0, |
| 67 | pci_xen_swiotlb_init, |
| 68 | 0); |