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

Function vm_iommu_modify

freebsd/amd64/vmm/vmm.c:878–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

876}
877
878static void
879vm_iommu_modify(struct vm *vm, bool map)
880{
881 int i, sz;
882 vm_paddr_t gpa, hpa;
883 struct mem_map *mm;
884 void *vp, *cookie, *host_domain;
885
886 sz = PAGE_SIZE;
887 host_domain = iommu_host_domain();
888
889 for (i = 0; i < VM_MAX_MEMMAPS; i++) {
890 mm = &vm->mem_maps[i];
891 if (!sysmem_mapping(vm, mm))
892 continue;
893
894 if (map) {
895 KASSERT((mm->flags & VM_MEMMAP_F_IOMMU) == 0,
896 ("iommu map found invalid memmap %#lx/%#lx/%#x",
897 mm->gpa, mm->len, mm->flags));
898 if ((mm->flags & VM_MEMMAP_F_WIRED) == 0)
899 continue;
900 mm->flags |= VM_MEMMAP_F_IOMMU;
901 } else {
902 if ((mm->flags & VM_MEMMAP_F_IOMMU) == 0)
903 continue;
904 mm->flags &= ~VM_MEMMAP_F_IOMMU;
905 KASSERT((mm->flags & VM_MEMMAP_F_WIRED) != 0,
906 ("iommu unmap found invalid memmap %#lx/%#lx/%#x",
907 mm->gpa, mm->len, mm->flags));
908 }
909
910 gpa = mm->gpa;
911 while (gpa < mm->gpa + mm->len) {
912 vp = vm_gpa_hold(vm, -1, gpa, PAGE_SIZE, VM_PROT_WRITE,
913 &cookie);
914 KASSERT(vp != NULL, ("vm(%s) could not map gpa %#lx",
915 vm_name(vm), gpa));
916
917 vm_gpa_release(cookie);
918
919 hpa = DMAP_TO_PHYS((uintptr_t)vp);
920 if (map) {
921 iommu_create_mapping(vm->iommu, gpa, hpa, sz);
922 iommu_remove_mapping(host_domain, hpa, sz);
923 } else {
924 iommu_remove_mapping(vm->iommu, gpa, sz);
925 iommu_create_mapping(host_domain, hpa, hpa, sz);
926 }
927
928 gpa += PAGE_SIZE;
929 }
930 }
931
932 /*
933 * Invalidate the cached translations associated with the domain
934 * from which pages were removed.
935 */

Callers

nothing calls this directly

Calls 8

iommu_host_domainFunction · 0.85
sysmem_mappingFunction · 0.85
vm_gpa_holdFunction · 0.85
vm_nameFunction · 0.85
vm_gpa_releaseFunction · 0.85
iommu_create_mappingFunction · 0.85
iommu_remove_mappingFunction · 0.85
iommu_invalidate_tlbFunction · 0.85

Tested by

no test coverage detected