blob: b480d4207a4cb23e584c40b5147f35a24872b8f2 [file] [log] [blame]
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -05001/* Glue code to lib/swiotlb-xen.c */
2
3#include <linux/dma-mapping.h>
Konrad Rzeszutek Wilk74226b82010-08-19 13:34:58 -04004#include <linux/pci.h>
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -05005#include <xen/swiotlb-xen.h>
6
7#include <asm/xen/hypervisor.h>
8#include <xen/xen.h>
Konrad Rzeszutek Wilk5cb3a262010-08-26 13:58:01 -04009#include <asm/iommu_table.h>
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050010
11int xen_swiotlb __read_mostly;
12
13static struct dma_map_ops xen_swiotlb_dma_ops = {
14 .mapping_error = xen_swiotlb_dma_mapping_error,
15 .alloc_coherent = xen_swiotlb_alloc_coherent,
16 .free_coherent = xen_swiotlb_free_coherent,
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 */
34int __init pci_xen_swiotlb_detect(void)
35{
36
37 /* If running as PV guest, either iommu=soft, or swiotlb=force will
38 * activate this IOMMU. If running as PV privileged, activate it
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020039 * irregardless.
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050040 */
41 if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
42 (xen_pv_domain()))
43 xen_swiotlb = 1;
44
45 /* If we are running under Xen, we MUST disable the native SWIOTLB.
46 * Don't worry about swiotlb_force flag activating the native, as
47 * the 'swiotlb' flag is the only one turning it on. */
48 if (xen_pv_domain())
49 swiotlb = 0;
50
51 return xen_swiotlb;
52}
53
54void __init pci_xen_swiotlb_init(void)
55{
56 if (xen_swiotlb) {
57 xen_swiotlb_init(1);
58 dma_ops = &xen_swiotlb_dma_ops;
Konrad Rzeszutek Wilk74226b82010-08-19 13:34:58 -040059
60 /* Make sure ACS will be enabled */
61 pci_request_acs();
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050062 }
63}
Konrad Rzeszutek Wilk5cb3a262010-08-26 13:58:01 -040064IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
65 0,
66 pci_xen_swiotlb_init,
67 0);