/* Does the reverse of the __map_single function. Must be called with the domain lock held too  */
static void __unmap_single(struct dma_ops_domain *dma_dom, dma_addr_t dma_addr, size_t size, int dir)
/* Does the reverse of the __map_single function. Must be called with the domain lock held too  */
static void __unmap_single(struct dma_ops_domain *dma_dom, dma_addr_t dma_addr, size_t size, int dir)
{
	dma_addr_t i, start;
	unsigned int pages;
	if ((dma_addr == DMA_ERROR_CODE) ||
	    (dma_addr + size > dma_dom->aperture_size))
		return;
	pages = iommu_num_pages(dma_addr, size, PAGE_SIZE);
	dma_addr &= PAGE_MASK;
	start = dma_addr;
	for (i = 0; i < pages; ++i) {
		dma_ops_domain_unmap(dma_dom, start);
		start += PAGE_SIZE;
	}
	SUB_STATS_COUNTER(alloced_io_mem, size);
	dma_ops_free_addresses(dma_dom, dma_addr, pages);
	if (amd_iommu_unmap_flush || dma_dom->need_flush) {
		iommu_flush_pages(&dma_dom->domain, dma_addr, size);
		dma_dom->need_flush = false;
	}
}