MCPcopy Create free account
hub / github.com/F-Stack/f-stack / dmar_domain_alloc

Function dmar_domain_alloc

freebsd/x86/iommu/intel_ctx.c:380–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378}
379
380static struct dmar_domain *
381dmar_domain_alloc(struct dmar_unit *dmar, bool id_mapped)
382{
383 struct iommu_domain *iodom;
384 struct iommu_unit *unit;
385 struct dmar_domain *domain;
386 int error, id, mgaw;
387
388 id = alloc_unr(dmar->domids);
389 if (id == -1)
390 return (NULL);
391 domain = malloc(sizeof(*domain), M_DMAR_DOMAIN, M_WAITOK | M_ZERO);
392 iodom = DOM2IODOM(domain);
393 unit = DMAR2IOMMU(dmar);
394 domain->domain = id;
395 LIST_INIT(&domain->contexts);
396 iommu_domain_init(unit, iodom, &dmar_domain_map_ops);
397
398 domain->dmar = dmar;
399
400 /*
401 * For now, use the maximal usable physical address of the
402 * installed memory to calculate the mgaw on id_mapped domain.
403 * It is useful for the identity mapping, and less so for the
404 * virtualized bus address space.
405 */
406 domain->iodom.end = id_mapped ? ptoa(Maxmem) : BUS_SPACE_MAXADDR;
407 mgaw = dmar_maxaddr2mgaw(dmar, domain->iodom.end, !id_mapped);
408 error = domain_set_agaw(domain, mgaw);
409 if (error != 0)
410 goto fail;
411 if (!id_mapped)
412 /* Use all supported address space for remapping. */
413 domain->iodom.end = 1ULL << (domain->agaw - 1);
414
415 iommu_gas_init_domain(DOM2IODOM(domain));
416
417 if (id_mapped) {
418 if ((dmar->hw_ecap & DMAR_ECAP_PT) == 0) {
419 domain->pgtbl_obj = domain_get_idmap_pgtbl(domain,
420 domain->iodom.end);
421 }
422 domain->iodom.flags |= IOMMU_DOMAIN_IDMAP;
423 } else {
424 error = domain_alloc_pgtbl(domain);
425 if (error != 0)
426 goto fail;
427 /* Disable local apic region access */
428 error = iommu_gas_reserve_region(iodom, 0xfee00000,
429 0xfeefffff + 1, &iodom->msi_entry);
430 if (error != 0)
431 goto fail;
432 }
433 return (domain);
434
435fail:
436 dmar_domain_destroy(domain);
437 return (NULL);

Callers 1

dmar_get_ctx_for_dev1Function · 0.85

Calls 7

alloc_unrFunction · 0.85
mallocFunction · 0.85
dmar_maxaddr2mgawFunction · 0.85
domain_set_agawFunction · 0.85
domain_get_idmap_pgtblFunction · 0.85
domain_alloc_pgtblFunction · 0.85
dmar_domain_destroyFunction · 0.85

Tested by

no test coverage detected