blob: 1ab45941502d6ca71238ca2f33897dd3e75b496e [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
Konrad Rzeszutek Wilkb8b0f552012-08-21 14:49:34 -040011#include <asm/xen/swiotlb-xen.h>
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050012int xen_swiotlb __read_mostly;
13
14static struct dma_map_ops xen_swiotlb_dma_ops = {
15 .mapping_error = xen_swiotlb_dma_mapping_error,
Andrzej Pietrasiewiczbaa676f2012-03-27 14:28:18 +020016 .alloc = xen_swiotlb_alloc_coherent,
17 .free = xen_swiotlb_free_coherent,
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050018 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
19 .sync_single_for_device = xen_swiotlb_sync_single_for_device,
20 .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
21 .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
22 .map_sg = xen_swiotlb_map_sg_attrs,
23 .unmap_sg = xen_swiotlb_unmap_sg_attrs,
24 .map_page = xen_swiotlb_map_page,
25 .unmap_page = xen_swiotlb_unmap_page,
26 .dma_supported = xen_swiotlb_dma_supported,
27};
28
29/*
30 * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
31 *
32 * This returns non-zero if we are forced to use xen_swiotlb (by the boot
33 * option).
34 */
35int __init pci_xen_swiotlb_detect(void)
36{
37
38 /* If running as PV guest, either iommu=soft, or swiotlb=force will
39 * activate this IOMMU. If running as PV privileged, activate it
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020040 * irregardless.
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050041 */
42 if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
43 (xen_pv_domain()))
44 xen_swiotlb = 1;
45
46 /* If we are running under Xen, we MUST disable the native SWIOTLB.
47 * Don't worry about swiotlb_force flag activating the native, as
48 * the 'swiotlb' flag is the only one turning it on. */
49 if (xen_pv_domain())
50 swiotlb = 0;
51
52 return xen_swiotlb;
53}
54
55void __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 Wilk74226b82010-08-19 13:34:58 -040060
61 /* Make sure ACS will be enabled */
62 pci_request_acs();
Konrad Rzeszutek Wilkbbbe5732010-02-09 14:30:55 -050063 }
64}
Konrad Rzeszutek Wilk5cb3a262010-08-26 13:58:01 -040065IOMMU_INIT_FINISH(pci_xen_swiotlb_detect,
Konrad Rzeszutek Wilk6d7083e2012-08-13 11:00:08 -040066 NULL,
Konrad Rzeszutek Wilk5cb3a262010-08-26 13:58:01 -040067 pci_xen_swiotlb_init,
Konrad Rzeszutek Wilk6d7083e2012-08-13 11:00:08 -040068 NULL);