/* This is the generic map function. It maps one 4kb page at paddr to the given address in the DMA address space for the domain.  */
static dma_addr_t dma_ops_domain_map(struct dma_ops_domain *dom, unsigned long address, phys_addr_t paddr, int direction)
/* This is the generic map function. It maps one 4kb page at paddr to the given address in the DMA address space for the domain.  */
static dma_addr_t dma_ops_domain_map(struct dma_ops_domain *dom, unsigned long address, phys_addr_t paddr, int direction)
{
	u64 *pte, __pte;
	WARN_ON(address > dom->aperture_size);
	paddr &= PAGE_MASK;
	pte  = dma_ops_get_pte(dom, address);
	if (!pte)
		return DMA_ERROR_CODE;
	__pte = paddr | IOMMU_PTE_P | IOMMU_PTE_FC;
	if (direction == DMA_TO_DEVICE)
		__pte |= IOMMU_PTE_IR;
	else if (direction == DMA_FROM_DEVICE)
		__pte |= IOMMU_PTE_IW;
	else if (direction == DMA_BIDIRECTIONAL)
		__pte |= IOMMU_PTE_IR | IOMMU_PTE_IW;
	WARN_ON(*pte);
	*pte = __pte;
	return (dma_addr_t)address;
}