On Wed, Jul 23, 2014 at 10:49:55AM -0700, Olav Haugan wrote: > On 7/22/2014 12:45 AM, Thierry Reding wrote: > > On Mon, Jul 21, 2014 at 05:59:22PM -0700, Olav Haugan wrote: > >> On 7/17/2014 1:21 AM, Thierry Reding wrote: > >>> On Wed, Jul 16, 2014 at 06:01:57PM -0700, Olav Haugan wrote: > > [...] > >>>> Additionally, the mapping operation would be faster in general since > >>>> clients does not have to keep calling map API over and over again for > >>>> each physically contiguous chunk of memory that needs to be mapped to a > >>>> virtually contiguous region. > >>>> > >>>> Signed-off-by: Olav Haugan <ohaugan@xxxxxxxxxxxxxx> > >>>> --- > >>>> drivers/iommu/iommu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > >>>> include/linux/iommu.h | 25 +++++++++++++++++++++++++ > >>>> 2 files changed, 73 insertions(+) > >>>> > >>>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > >>>> index 1698360..a0eebb7 100644 > >>>> --- a/drivers/iommu/iommu.c > >>>> +++ b/drivers/iommu/iommu.c > >>>> @@ -1089,6 +1089,54 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) > >>>> EXPORT_SYMBOL_GPL(iommu_unmap); > >>>> > >>>> > >>>> +int iommu_map_range(struct iommu_domain *domain, unsigned int iova, > >>> > >>> Maybe iova should be dma_addr_t? Or at least unsigned long? And perhaps > >>> iommu_map_sg() would be more consistent with the equivalent function in > >>> struct dma_ops? > >>> > >>>> + struct scatterlist *sg, unsigned int len, int opt) > >>> > >>> The length argument seems to be the size of the mapping. Again, the > >>> struct dma_ops function uses this argument to denote the number of > >>> entries in the scatterlist. > >>> > >>> opt is somewhat opaque. Perhaps this should be turned into unsigned long > >>> flags? Although given that there aren't any users yet it's difficult to > >>> say what's best here. Perhaps the addition of this argument should be > >>> postponed until there are actual users? > >> > >> I am thinking something like this: > >> > >> int iommu_map_sg(struct iommu_domain *domain, struct scatterlist *sg, > >> unsigned int nents, int prot, unsigned long flags); > >> int iommu_unmap_sg(struct iommu_domain *domain, struct scatterlist *sg, > >> unsigned int nents, unsigned long flags); > > > > Looks good. > > > >> The iova is contained within sg so we don't need that argument really > > > > I'm not sure. I think a common use-case for this function is for some > > driver to map an imported DMA-BUF. In that case you'll get a struct > > sg_table, but I think it won't have sg.dma_address set to anything > > useful. So if we don't have iova as a parameter to this function, the > > driver would have to make it a two-step process, like this: > > > > sg_dma_address(sg) = iova; > > > > err = iommu_map_sg(...); > > > > And drivers that use the IOMMU API directly need to manage IOVA space > > themselves anyway, so I think passing around the IOVA within the SG > > won't be a very common case. It will almost always be the driver that > > calls this function which allocates the IOVA range. > > Yes, I see your point. Rob is not a fan either... > So what about this: > > int iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct > scatterlist *sg, unsigned int nents, int prot, unsigned long flags); > int iommu_unmap_sg(struct iommu_domain *domain, unsigned long iova, > size_t size, unsigned long flags); > > No need for sg in the unmap call then. Keeping iova an unsigned long to > match the existing iommu_map/iommu_unmap calls. Looks good to me. I think we may want to eventually convert iova to dma_addr_t since that's a more appropriate type for these addresses but we can do that in a separate patch later on. [...] > > For .map_sg() I think pretty much every driver will want to implement > > it, so requiring developers to explicitly set it for their driver seems > > like a good idea. If there's no advantage in implementing it then they > > can always get the same functionality by explicitly using the fallback. > > I feel that requiring drivers to set the default callback defeats the > purpose of having a fallback in the first place. The reason to provide > the default fallback is to catch any driver that does not implement this > themselves. Certainly, but the exact same can be achieved by making all drivers point to the generic implementation. In my opinion that makes it much more explicit (and therefore obvious) what's really going on. Hiding fallbacks in the core API obfuscates. And this is all in-tree code, so we have full control over what we change, so the patch that introduces this new API could simply make the necessary adjustments to existing drivers. Thierry
Attachment:
pgpUx3Gck9yr2.pgp
Description: PGP signature