ALSA: hda - Add static_hdmi_pcm option to HDMI codec parser
[linux-2.6/next.git] / drivers / base / iommu.c
blob6e6b6a11b3ced64d1c90e3c9d35d25823f6b5ccf
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/module.h>
22 #include <linux/slab.h>
23 #include <linux/errno.h>
24 #include <linux/iommu.h>
26 static struct iommu_ops *iommu_ops;
28 void register_iommu(struct iommu_ops *ops)
30 if (iommu_ops)
31 BUG();
33 iommu_ops = ops;
36 bool iommu_found(void)
38 return iommu_ops != NULL;
40 EXPORT_SYMBOL_GPL(iommu_found);
42 struct iommu_domain *iommu_domain_alloc(void)
44 struct iommu_domain *domain;
45 int ret;
47 domain = kmalloc(sizeof(*domain), GFP_KERNEL);
48 if (!domain)
49 return NULL;
51 ret = iommu_ops->domain_init(domain);
52 if (ret)
53 goto out_free;
55 return domain;
57 out_free:
58 kfree(domain);
60 return NULL;
62 EXPORT_SYMBOL_GPL(iommu_domain_alloc);
64 void iommu_domain_free(struct iommu_domain *domain)
66 iommu_ops->domain_destroy(domain);
67 kfree(domain);
69 EXPORT_SYMBOL_GPL(iommu_domain_free);
71 int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
73 return iommu_ops->attach_dev(domain, dev);
75 EXPORT_SYMBOL_GPL(iommu_attach_device);
77 void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
79 iommu_ops->detach_dev(domain, dev);
81 EXPORT_SYMBOL_GPL(iommu_detach_device);
83 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
84 unsigned long iova)
86 return iommu_ops->iova_to_phys(domain, iova);
88 EXPORT_SYMBOL_GPL(iommu_iova_to_phys);
90 int iommu_domain_has_cap(struct iommu_domain *domain,
91 unsigned long cap)
93 return iommu_ops->domain_has_cap(domain, cap);
95 EXPORT_SYMBOL_GPL(iommu_domain_has_cap);
97 int iommu_map(struct iommu_domain *domain, unsigned long iova,
98 phys_addr_t paddr, int gfp_order, int prot)
100 unsigned long invalid_mask;
101 size_t size;
103 size = 0x1000UL << gfp_order;
104 invalid_mask = size - 1;
106 BUG_ON((iova | paddr) & invalid_mask);
108 return iommu_ops->map(domain, iova, paddr, gfp_order, prot);
110 EXPORT_SYMBOL_GPL(iommu_map);
112 int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order)
114 unsigned long invalid_mask;
115 size_t size;
117 size = 0x1000UL << gfp_order;
118 invalid_mask = size - 1;
120 BUG_ON(iova & invalid_mask);
122 return iommu_ops->unmap(domain, iova, gfp_order);
124 EXPORT_SYMBOL_GPL(iommu_unmap);