int iommu_alloc(struct acpi_drhd_unit *drhd);
void iommu_free(struct acpi_drhd_unit *drhd);
+domid_t did_to_domain_id(const struct vtd_iommu *iommu, unsigned int did);
+
int iommu_flush_iec_global(struct vtd_iommu *iommu);
int iommu_flush_iec_index(struct vtd_iommu *iommu, u8 im, u16 iidx);
void clear_fault_bits(struct vtd_iommu *iommu);
if ( iommu && context )
{
- unsigned int nr_dom = cap_ndoms(iommu->cap);
unsigned int dom_index = context_domain_id(*context);
- if ( dom_index < nr_dom && iommu->domid_map )
- domid = iommu->domid_map[dom_index];
- else
+ domid = did_to_domain_id(iommu, dom_index);
+ if ( domid == DOMID_INVALID )
+ {
dprintk(XENLOG_DEBUG VTDPREFIX,
- "dom_index %u exceeds nr_dom %u or iommu has no domid_map\n",
- dom_index, nr_dom);
+ "no domid for did %u (nr_dom %u)\n",
+ dom_index, cap_ndoms(iommu->cap));
+ domid = -1;
+ }
}
return domid;
}
}
+domid_t did_to_domain_id(const struct vtd_iommu *iommu, unsigned int did)
+{
+ if ( did >= cap_ndoms(iommu->cap) || !test_bit(did, iommu->domid_bitmap) )
+ return DOMID_INVALID;
+
+ return iommu->domid_map[did];
+}
+
static void sync_cache(const void *addr, unsigned int size)
{
static unsigned long clflush_size = 0;
rc = queue_invalidate_wait(iommu, 0, 1, 1, 1);
if ( rc == -ETIMEDOUT )
{
- struct domain *d = NULL;
-
- if ( test_bit(did, iommu->domid_bitmap) )
- d = rcu_lock_domain_by_id(iommu->domid_map[did]);
+ struct domain *d = rcu_lock_domain_by_id(did_to_domain_id(iommu, did));
/*
* In case the domain has been freed or the IOMMU domid bitmap is