Now it works.
[cbs-scheduler.git] / drivers / base / iommu.c
blobc2d1eed903767484304b1f3208c27719b5ec3195
1 /*
2 * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
3 * Author: Joerg Roedel <joerg.roedel@amd.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/bug.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/iommu.h>
24 static struct iommu_ops *iommu_ops;
26 void register_iommu(struct iommu_ops *ops)
28 if (iommu_ops)
29 BUG();
31 iommu_ops = ops;
34 bool iommu_found(void)
36 return iommu_ops != NULL;
38 EXPORT_SYMBOL_GPL(iommu_found);
40 struct iommu_domain *iommu_domain_alloc(void)
42 struct iommu_domain *domain;
43 int ret;
45 domain = kmalloc(sizeof(*domain), GFP_KERNEL);
46 if (!domain)
47 return NULL;
49 ret = iommu_ops->domain_init(domain);
50 if (ret)
51 goto out_free;
53 return domain;
55 out_free:
56 kfree(domain);
58 return NULL;
60 EXPORT_SYMBOL_GPL(iommu_domain_alloc);
62 void iommu_domain_free(struct iommu_domain *domain)
64 iommu_ops->domain_destroy(domain);
65 kfree(domain);
67 EXPORT_SYMBOL_GPL(iommu_domain_free);
69 int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
71 return iommu_ops->attach_dev(domain, dev);
73 EXPORT_SYMBOL_GPL(iommu_attach_device);
75 void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
77 iommu_ops->detach_dev(domain, dev);
79 EXPORT_SYMBOL_GPL(iommu_detach_device);
81 int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
82 phys_addr_t paddr, size_t size, int prot)
84 return iommu_ops->map(domain, iova, paddr, size, prot);
86 EXPORT_SYMBOL_GPL(iommu_map_range);
88 void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
89 size_t size)
91 iommu_ops->unmap(domain, iova, size);
93 EXPORT_SYMBOL_GPL(iommu_unmap_range);
95 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
96 unsigned long iova)
98 return iommu_ops->iova_to_phys(domain, iova);
100 EXPORT_SYMBOL_GPL(iommu_iova_to_phys);