Commit 666c9f1e authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel

iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN

This brings back the ops->detach_dev() code that commit
1b932ced ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Also reverts commit 584d334b ("iommu/ipmmu-vmsa: Remove
ipmmu_utlb_disable()")
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/17-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.comSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 786478a9
...@@ -295,6 +295,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, ...@@ -295,6 +295,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
mmu->utlb_ctx[utlb] = domain->context_id; mmu->utlb_ctx[utlb] = domain->context_id;
} }
/*
* Disable MMU translation for the microTLB.
*/
static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain,
unsigned int utlb)
{
struct ipmmu_vmsa_device *mmu = domain->mmu;
ipmmu_imuctr_write(mmu, utlb, 0);
mmu->utlb_ctx[utlb] = IPMMU_CTX_INVALID;
}
static void ipmmu_tlb_flush_all(void *cookie) static void ipmmu_tlb_flush_all(void *cookie)
{ {
struct ipmmu_vmsa_domain *domain = cookie; struct ipmmu_vmsa_domain *domain = cookie;
...@@ -627,6 +639,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, ...@@ -627,6 +639,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
return 0; return 0;
} }
static int ipmmu_iommu_identity_attach(struct iommu_domain *identity_domain,
struct device *dev)
{
struct iommu_domain *io_domain = iommu_get_domain_for_dev(dev);
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct ipmmu_vmsa_domain *domain;
unsigned int i;
if (io_domain == identity_domain || !io_domain)
return 0;
domain = to_vmsa_domain(io_domain);
for (i = 0; i < fwspec->num_ids; ++i)
ipmmu_utlb_disable(domain, fwspec->ids[i]);
/*
* TODO: Optimize by disabling the context when no device is attached.
*/
return 0;
}
static struct iommu_domain_ops ipmmu_iommu_identity_ops = {
.attach_dev = ipmmu_iommu_identity_attach,
};
static struct iommu_domain ipmmu_iommu_identity_domain = {
.type = IOMMU_DOMAIN_IDENTITY,
.ops = &ipmmu_iommu_identity_ops,
};
static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova,
phys_addr_t paddr, size_t pgsize, size_t pgcount, phys_addr_t paddr, size_t pgsize, size_t pgcount,
int prot, gfp_t gfp, size_t *mapped) int prot, gfp_t gfp, size_t *mapped)
...@@ -849,6 +891,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) ...@@ -849,6 +891,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)
} }
static const struct iommu_ops ipmmu_ops = { static const struct iommu_ops ipmmu_ops = {
.identity_domain = &ipmmu_iommu_identity_domain,
.domain_alloc = ipmmu_domain_alloc, .domain_alloc = ipmmu_domain_alloc,
.probe_device = ipmmu_probe_device, .probe_device = ipmmu_probe_device,
.release_device = ipmmu_release_device, .release_device = ipmmu_release_device,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment