/* The exported map_sg function for dma_ops (handles scatter-gather lists).  */
static void unmap_sg(struct device *dev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs)
/* The exported map_sg function for dma_ops (handles scatter-gather lists).  */
static void unmap_sg(struct device *dev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs)
{
	unsigned long flags;
	struct protection_domain *domain;
	struct scatterlist *s;
	int i;
	INC_STATS_COUNTER(cnt_unmap_sg);
	domain = get_domain(dev);
	if (IS_ERR(domain))
		return;
	spin_lock_irqsave(&domain->lock, flags);
	for_each_sg(sglist, s, nelems, i) {
		__unmap_single(domain->priv, s->dma_address,
			       s->dma_length, dir);
		s->dma_address = s->dma_length = 0;
	}
	iommu_flush_complete(domain);
	spin_unlock_irqrestore(&domain->lock, flags);
}