iommu/vt-d: Calculate translation in domain_context_mapping_one
There is no reason to pass the translation type through multiple layers. It can also be determined in the domain_context_mapping_one function directly. Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
e2411427f7
commit
28ccce0d95
|
@ -364,7 +364,8 @@ static inline int first_pte_in_page(struct dma_pte *pte)
|
||||||
static struct dmar_domain *si_domain;
|
static struct dmar_domain *si_domain;
|
||||||
static int hw_pass_through = 1;
|
static int hw_pass_through = 1;
|
||||||
|
|
||||||
/* domain represents a virtual machine, more than one devices
|
/*
|
||||||
|
* Domain represents a virtual machine, more than one devices
|
||||||
* across iommus may be owned in one domain, e.g. kvm guest.
|
* across iommus may be owned in one domain, e.g. kvm guest.
|
||||||
*/
|
*/
|
||||||
#define DOMAIN_FLAG_VIRTUAL_MACHINE (1 << 0)
|
#define DOMAIN_FLAG_VIRTUAL_MACHINE (1 << 0)
|
||||||
|
@ -640,6 +641,11 @@ static inline int domain_type_is_vm(struct dmar_domain *domain)
|
||||||
return domain->flags & DOMAIN_FLAG_VIRTUAL_MACHINE;
|
return domain->flags & DOMAIN_FLAG_VIRTUAL_MACHINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int domain_type_is_si(struct dmar_domain *domain)
|
||||||
|
{
|
||||||
|
return domain->flags & DOMAIN_FLAG_STATIC_IDENTITY;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int domain_type_is_vm_or_si(struct dmar_domain *domain)
|
static inline int domain_type_is_vm_or_si(struct dmar_domain *domain)
|
||||||
{
|
{
|
||||||
return domain->flags & (DOMAIN_FLAG_VIRTUAL_MACHINE |
|
return domain->flags & (DOMAIN_FLAG_VIRTUAL_MACHINE |
|
||||||
|
@ -1907,21 +1913,23 @@ static void domain_exit(struct dmar_domain *domain)
|
||||||
|
|
||||||
static int domain_context_mapping_one(struct dmar_domain *domain,
|
static int domain_context_mapping_one(struct dmar_domain *domain,
|
||||||
struct intel_iommu *iommu,
|
struct intel_iommu *iommu,
|
||||||
u8 bus, u8 devfn, int translation)
|
u8 bus, u8 devfn)
|
||||||
{
|
{
|
||||||
|
int translation = CONTEXT_TT_MULTI_LEVEL;
|
||||||
|
struct device_domain_info *info = NULL;
|
||||||
struct context_entry *context;
|
struct context_entry *context;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct dma_pte *pgd;
|
struct dma_pte *pgd;
|
||||||
int id;
|
int id;
|
||||||
int agaw;
|
int agaw;
|
||||||
struct device_domain_info *info = NULL;
|
|
||||||
|
if (hw_pass_through && domain_type_is_si(domain))
|
||||||
|
translation = CONTEXT_TT_PASS_THROUGH;
|
||||||
|
|
||||||
pr_debug("Set context mapping for %02x:%02x.%d\n",
|
pr_debug("Set context mapping for %02x:%02x.%d\n",
|
||||||
bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
|
bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||||||
|
|
||||||
BUG_ON(!domain->pgd);
|
BUG_ON(!domain->pgd);
|
||||||
BUG_ON(translation != CONTEXT_TT_PASS_THROUGH &&
|
|
||||||
translation != CONTEXT_TT_MULTI_LEVEL);
|
|
||||||
|
|
||||||
spin_lock_irqsave(&iommu->lock, flags);
|
spin_lock_irqsave(&iommu->lock, flags);
|
||||||
context = iommu_context_addr(iommu, bus, devfn, 1);
|
context = iommu_context_addr(iommu, bus, devfn, 1);
|
||||||
|
@ -2013,7 +2021,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
|
||||||
struct domain_context_mapping_data {
|
struct domain_context_mapping_data {
|
||||||
struct dmar_domain *domain;
|
struct dmar_domain *domain;
|
||||||
struct intel_iommu *iommu;
|
struct intel_iommu *iommu;
|
||||||
int translation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int domain_context_mapping_cb(struct pci_dev *pdev,
|
static int domain_context_mapping_cb(struct pci_dev *pdev,
|
||||||
|
@ -2022,13 +2029,11 @@ static int domain_context_mapping_cb(struct pci_dev *pdev,
|
||||||
struct domain_context_mapping_data *data = opaque;
|
struct domain_context_mapping_data *data = opaque;
|
||||||
|
|
||||||
return domain_context_mapping_one(data->domain, data->iommu,
|
return domain_context_mapping_one(data->domain, data->iommu,
|
||||||
PCI_BUS_NUM(alias), alias & 0xff,
|
PCI_BUS_NUM(alias), alias & 0xff);
|
||||||
data->translation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
domain_context_mapping(struct dmar_domain *domain, struct device *dev,
|
domain_context_mapping(struct dmar_domain *domain, struct device *dev)
|
||||||
int translation)
|
|
||||||
{
|
{
|
||||||
struct intel_iommu *iommu;
|
struct intel_iommu *iommu;
|
||||||
u8 bus, devfn;
|
u8 bus, devfn;
|
||||||
|
@ -2039,12 +2044,10 @@ domain_context_mapping(struct dmar_domain *domain, struct device *dev,
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
if (!dev_is_pci(dev))
|
if (!dev_is_pci(dev))
|
||||||
return domain_context_mapping_one(domain, iommu, bus, devfn,
|
return domain_context_mapping_one(domain, iommu, bus, devfn);
|
||||||
translation);
|
|
||||||
|
|
||||||
data.domain = domain;
|
data.domain = domain;
|
||||||
data.iommu = iommu;
|
data.iommu = iommu;
|
||||||
data.translation = translation;
|
|
||||||
|
|
||||||
return pci_for_each_dma_alias(to_pci_dev(dev),
|
return pci_for_each_dma_alias(to_pci_dev(dev),
|
||||||
&domain_context_mapping_cb, &data);
|
&domain_context_mapping_cb, &data);
|
||||||
|
@ -2511,7 +2514,7 @@ static int iommu_prepare_identity_map(struct device *dev,
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* context entry init */
|
/* context entry init */
|
||||||
ret = domain_context_mapping(domain, dev, CONTEXT_TT_MULTI_LEVEL);
|
ret = domain_context_mapping(domain, dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -2624,8 +2627,7 @@ static int identity_mapping(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int domain_add_dev_info(struct dmar_domain *domain,
|
static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
|
||||||
struct device *dev, int translation)
|
|
||||||
{
|
{
|
||||||
struct dmar_domain *ndomain;
|
struct dmar_domain *ndomain;
|
||||||
struct intel_iommu *iommu;
|
struct intel_iommu *iommu;
|
||||||
|
@ -2640,7 +2642,7 @@ static int domain_add_dev_info(struct dmar_domain *domain,
|
||||||
if (ndomain != domain)
|
if (ndomain != domain)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
ret = domain_context_mapping(domain, dev, translation);
|
ret = domain_context_mapping(domain, dev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
domain_remove_one_dev_info(domain, dev);
|
domain_remove_one_dev_info(domain, dev);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2785,9 +2787,7 @@ static int __init dev_prepare_static_identity_mapping(struct device *dev, int hw
|
||||||
if (!iommu_should_identity_map(dev, 1))
|
if (!iommu_should_identity_map(dev, 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = domain_add_dev_info(si_domain, dev,
|
ret = domain_add_dev_info(si_domain, dev);
|
||||||
hw ? CONTEXT_TT_PASS_THROUGH :
|
|
||||||
CONTEXT_TT_MULTI_LEVEL);
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
pr_info("%s identity mapping for device %s\n",
|
pr_info("%s identity mapping for device %s\n",
|
||||||
hw ? "Hardware" : "Software", dev_name(dev));
|
hw ? "Hardware" : "Software", dev_name(dev));
|
||||||
|
@ -3314,7 +3314,7 @@ static struct dmar_domain *__get_valid_domain_for_dev(struct device *dev)
|
||||||
|
|
||||||
/* make sure context mapping is ok */
|
/* make sure context mapping is ok */
|
||||||
if (unlikely(!domain_context_mapped(dev))) {
|
if (unlikely(!domain_context_mapped(dev))) {
|
||||||
ret = domain_context_mapping(domain, dev, CONTEXT_TT_MULTI_LEVEL);
|
ret = domain_context_mapping(domain, dev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("Domain context map for %s failed\n",
|
pr_err("Domain context map for %s failed\n",
|
||||||
dev_name(dev));
|
dev_name(dev));
|
||||||
|
@ -3369,10 +3369,7 @@ static int iommu_no_mapping(struct device *dev)
|
||||||
*/
|
*/
|
||||||
if (iommu_should_identity_map(dev, 0)) {
|
if (iommu_should_identity_map(dev, 0)) {
|
||||||
int ret;
|
int ret;
|
||||||
ret = domain_add_dev_info(si_domain, dev,
|
ret = domain_add_dev_info(si_domain, dev);
|
||||||
hw_pass_through ?
|
|
||||||
CONTEXT_TT_PASS_THROUGH :
|
|
||||||
CONTEXT_TT_MULTI_LEVEL);
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
pr_info("64bit %s uses identity mapping\n",
|
pr_info("64bit %s uses identity mapping\n",
|
||||||
dev_name(dev));
|
dev_name(dev));
|
||||||
|
@ -4810,7 +4807,7 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
|
||||||
dmar_domain->agaw--;
|
dmar_domain->agaw--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain_add_dev_info(dmar_domain, dev, CONTEXT_TT_MULTI_LEVEL);
|
return domain_add_dev_info(dmar_domain, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void intel_iommu_detach_device(struct iommu_domain *domain,
|
static void intel_iommu_detach_device(struct iommu_domain *domain,
|
||||||
|
|
Loading…
Reference in a new issue