/* Find out the protection domain structure for a given PCI device. This will give us the pointer to the page table root for example.  */
static struct protection_domain* domain_for_device(struct device *dev)
/* Find out the protection domain structure for a given PCI device. This will give us the pointer to the page table root for example.  */
static struct protection_domain* domain_for_device(struct device *dev)
{
	struct protection_domain *dom;
	struct iommu_dev_data *dev_data, *alias_data;
	unsigned long flags;
	u16 devid, alias;
	devid      = get_device_id(dev);
	alias      = amd_iommu_alias_table[devid];
	dev_data   = get_dev_data(dev);
	alias_data = get_dev_data(dev_data->alias);
	if (!alias_data)
		return NULL;
	read_lock_irqsave(&amd_iommu_devtable_lock, flags);
	dom = dev_data->domain;
	if (dom == NULL &&
	    alias_data->domain != NULL) {
		__attach_device(dev, alias_data->domain);
		dom = alias_data->domain;
	}
	read_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
	return dom;
}