/* In the dma_ops path we only have the struct device. This function finds the corresponding IOMMU, the protection domain and the requestor id for a given device. If the device is not yet associated with a domain this is also done in this function.  */
static struct protection_domain* get_domain(struct device *dev)
/* In the dma_ops path we only have the struct device. This function finds the corresponding IOMMU, the protection domain and the requestor id for a given device. If the device is not yet associated with a domain this is also done in this function.  */
static struct protection_domain* get_domain(struct device *dev)
{
	struct protection_domain *domain;
	struct dma_ops_domain *dma_dom;
	u16 devid = get_device_id(dev);
	if (!check_device(dev))
		return ERR_PTR(-EINVAL);
	domain = domain_for_device(dev);
	if (domain != NULL && !dma_ops_domain(domain))
		return ERR_PTR(-EBUSY);
	if (domain != NULL)
		return domain;
	dma_dom = find_protection_domain(devid);
	if (!dma_dom)
		dma_dom = amd_iommu_rlookup_table[devid]->default_dom;
	attach_device(dev, &dma_dom->domain);
	DUMP_printk("Using protection domain %d for device %s\n",
		    dma_dom->domain.id, dev_name(dev));
	return &dma_dom->domain;
}