Skip to content

Commit

Permalink
iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN
Browse files Browse the repository at this point in the history
This brings back the ops->detach_dev() code that commit
1b932ce ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Also reverts commit 584d334 ("iommu/ipmmu-vmsa: Remove
ipmmu_utlb_disable()")

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/17-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Jason Gunthorpe authored and Joerg Roedel committed Sep 25, 2023
1 parent 786478a commit 666c9f1
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions drivers/iommu/ipmmu-vmsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
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)
{
struct ipmmu_vmsa_domain *domain = cookie;
Expand Down Expand Up @@ -627,6 +639,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
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,
phys_addr_t paddr, size_t pgsize, size_t pgcount,
int prot, gfp_t gfp, size_t *mapped)
Expand Down Expand Up @@ -849,6 +891,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)
}

static const struct iommu_ops ipmmu_ops = {
.identity_domain = &ipmmu_iommu_identity_domain,
.domain_alloc = ipmmu_domain_alloc,
.probe_device = ipmmu_probe_device,
.release_device = ipmmu_release_device,
Expand Down

0 comments on commit 666c9f1

Please sign in to comment.