Hi Jörg,

On Wed, May 13, 2020 at 11:53:04AM +0200, Joerg Roedel wrote:
> On Tue, May 05, 2020 at 12:09:32PM +0200, Maxime Ripard wrote:
> > +static u32 *sun50i_dte_get_page_table(struct sun50i_iommu_domain 
> > *sun50i_domain,
> > +                                 dma_addr_t iova, gfp_t gfp)
> > +{
> > +   struct sun50i_iommu *iommu = sun50i_domain->iommu;
> > +   unsigned long flags;
> > +   u32 *page_table;
> > +   u32 *dte_addr;
> > +   u32 old_dte;
> > +   u32 dte;
> > +
> > +   dte_addr = &sun50i_domain->dt[sun50i_iova_get_dte_index(iova)];
> > +   dte = *dte_addr;
> > +   if (sun50i_dte_is_pt_valid(dte)) {
> > +           phys_addr_t pt_phys = sun50i_dte_get_pt_address(dte);
> > +           return (u32 *)phys_to_virt(pt_phys);
> > +   }
> > +
> > +   page_table = sun50i_iommu_alloc_page_table(iommu, gfp);
> > +   if (IS_ERR(page_table))
> > +           return page_table;
> > +
> > +   dte = sun50i_mk_dte(virt_to_phys(page_table));
> > +   old_dte = cmpxchg(dte_addr, 0, dte);
> > +   if (old_dte) {
> > +           phys_addr_t installed_pt_phys =
> > +                   sun50i_dte_get_pt_address(old_dte);
> > +           u32 *installed_pt = phys_to_virt(installed_pt_phys);
> > +           u32 *drop_pt = page_table;
> > +
> > +           page_table = installed_pt;
> > +           dte = old_dte;
> > +           sun50i_iommu_free_page_table(iommu, drop_pt);
> > +   }
> > +
> > +   sun50i_table_flush(sun50i_domain, page_table, PT_SIZE);
> > +   sun50i_table_flush(sun50i_domain, dte_addr, 1);
> > +
> > +   spin_lock_irqsave(&iommu->iommu_lock, flags);
> > +   sun50i_iommu_ptw_invalidate(iommu, iova);
> > +   spin_unlock_irqrestore(&iommu->iommu_lock, flags);
> 
> Why is that needed, does the PTW also cache non-present entries?

The documentation is pretty sparse, so I was conservative again. I've removed it
and it seems to be working fine in all the cases I could test, so I guess we're
fine without it :)

> > +static int sun50i_iommu_add_device(struct device *dev)
> > +{
> > +   struct sun50i_iommu *iommu;
> > +   struct iommu_group *group;
> > +
> > +   iommu = sun50i_iommu_from_dev(dev);
> > +   if (!iommu)
> > +           return -ENODEV;
> > +
> > +   group = iommu_group_get_for_dev(dev);
> > +   if (IS_ERR(group))
> > +           return PTR_ERR(group);
> > +
> > +   iommu_group_put(group);
> > +
> > +   return 0;
> > +}
> > +
> > +static void sun50i_iommu_remove_device(struct device *dev)
> > +{
> > +   iommu_group_remove_device(dev);
> > +}
> 
> 
> These two call-backs have been renamed in the iommu-tree to
> probe_device() and release_device() with slightly different semantics
> and function signatures. I think for this driver they should look like
> this:
> 
>       static struct iommu_device *sun50i_iommu_probe_device(struct device 
> *dev)
>       {
>               struct sun50i_iommu *iommu;
> 
>               iommu = sun50i_iommu_from_dev(dev);
>               if (!iommu)
>                       return ERR_PTR(-ENODEV);
> 
>               return &iommu->iommu;
>       }
> 
>       static void sun50i_iommu_release_device(struct device *dev)
>       {
>       }
> 
> Can you pleas rebase these patches to the 'core' branch of the
> iommu-tree and use these new call-backs?
> 
> The rest of your driver looks good to me. Good work!

I've rebased it on next, and it indeed works with your suggestion. I'll resend a
new version in a short while.

Thanks!
Maxime

Attachment: signature.asc
Description: PGP signature

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to