static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)

{

    VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);

    VFIOContainer *container = giommu->container;

    hwaddr iova = iotlb->iova + giommu->iommu_offset;

    MemoryRegion *mr;

    hwaddr xlat;

    hwaddr len = iotlb->addr_mask + 1;

    void *vaddr;

    int ret;



    trace_vfio_iommu_map_notify(iotlb->perm == IOMMU_NONE ? "UNMAP" : "MAP",

                                iova, iova + iotlb->addr_mask);



    if (iotlb->target_as != &address_space_memory) {

        error_report("Wrong target AS \"%s\", only system memory is allowed",

                     iotlb->target_as->name ? iotlb->target_as->name : "none");

        return;

    }



    /*

     * The IOMMU TLB entry we have just covers translation through

     * this IOMMU to its immediate target.  We need to translate

     * it the rest of the way through to memory.

     */

    rcu_read_lock();

    mr = address_space_translate(&address_space_memory,

                                 iotlb->translated_addr,

                                 &xlat, &len, iotlb->perm & IOMMU_WO);

    if (!memory_region_is_ram(mr)) {

        error_report("iommu map to non memory area %"HWADDR_PRIx"",

                     xlat);

        goto out;

    }

    /*

     * Translation truncates length to the IOMMU page size,

     * check that it did not truncate too much.

     */

    if (len & iotlb->addr_mask) {

        error_report("iommu has granularity incompatible with target AS");

        goto out;

    }



    if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {

        vaddr = memory_region_get_ram_ptr(mr) + xlat;

        ret = vfio_dma_map(container, iova,

                           iotlb->addr_mask + 1, vaddr,

                           !(iotlb->perm & IOMMU_WO) || mr->readonly);

        if (ret) {

            error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx", %p) = %d (%m)",

                         container, iova,

                         iotlb->addr_mask + 1, vaddr, ret);

        }

    } else {

        ret = vfio_dma_unmap(container, iova, iotlb->addr_mask + 1);

        if (ret) {

            error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx") = %d (%m)",

                         container, iova,

                         iotlb->addr_mask + 1, ret);

        }

    }

out:

    rcu_read_unlock();

}

static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)

{

    VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);

    VFIOContainer *container = giommu->container;

    hwaddr iova = iotlb->iova + giommu->iommu_offset;

    MemoryRegion *mr;

    hwaddr xlat;

    hwaddr len = iotlb->addr_mask + 1;

    void *vaddr;

    int ret;



    trace_vfio_iommu_map_notify(iotlb->perm == IOMMU_NONE ? "UNMAP" : "MAP",

                                iova, iova + iotlb->addr_mask);



    if (iotlb->target_as != &address_space_memory) {

        error_report("Wrong target AS \"%s\", only system memory is allowed",

                     iotlb->target_as->name ? iotlb->target_as->name : "none");

        return;

    }



    









    rcu_read_lock();

    mr = address_space_translate(&address_space_memory,

                                 iotlb->translated_addr,

                                 &xlat, &len, iotlb->perm & IOMMU_WO);

    if (!memory_region_is_ram(mr)) {

        error_report("iommu map to non memory area %"HWADDR_PRIx"",

                     xlat);

        goto out;

    }

    







    if (len & iotlb->addr_mask) {

        error_report("iommu has granularity incompatible with target AS");

        goto out;

    }



    if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {

        vaddr = memory_region_get_ram_ptr(mr) + xlat;

        ret = vfio_dma_map(container, iova,

                           iotlb->addr_mask + 1, vaddr,

                           !(iotlb->perm & IOMMU_WO) || mr->readonly);

        if (ret) {

            error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx", %p) = %d (%m)",

                         container, iova,

                         iotlb->addr_mask + 1, vaddr, ret);

        }

    } else {

        ret = vfio_dma_unmap(container, iova, iotlb->addr_mask + 1);

        if (ret) {

            error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx") = %d (%m)",

                         container, iova,

                         iotlb->addr_mask + 1, ret);

        }

    }

out:

    rcu_read_unlock();

}

static void FUNC_0(IOMMUNotifier *VAR_0, IOMMUTLBEntry *VAR_1)

{

    VFIOGuestIOMMU *giommu = container_of(VAR_0, VFIOGuestIOMMU, VAR_0);

    VFIOContainer *container = giommu->container;

    hwaddr iova = VAR_1->iova + giommu->iommu_offset;

    MemoryRegion *mr;

    hwaddr xlat;

    hwaddr len = VAR_1->addr_mask + 1;

    void *VAR_2;

    int VAR_3;



    trace_vfio_iommu_map_notify(VAR_1->perm == IOMMU_NONE ? "UNMAP" : "MAP",

                                iova, iova + VAR_1->addr_mask);



    if (VAR_1->target_as != &address_space_memory) {

        error_report("Wrong target AS \"%s\", only system memory is allowed",

                     VAR_1->target_as->name ? VAR_1->target_as->name : "none");

        return;

    }



    









    rcu_read_lock();

    mr = address_space_translate(&address_space_memory,

                                 VAR_1->translated_addr,

                                 &xlat, &len, VAR_1->perm & IOMMU_WO);

    if (!memory_region_is_ram(mr)) {

        error_report("iommu map to non memory area %"HWADDR_PRIx"",

                     xlat);

        goto out;

    }

    







    if (len & VAR_1->addr_mask) {

        error_report("iommu has granularity incompatible with target AS");

        goto out;

    }



    if ((VAR_1->perm & IOMMU_RW) != IOMMU_NONE) {

        VAR_2 = memory_region_get_ram_ptr(mr) + xlat;

        VAR_3 = vfio_dma_map(container, iova,

                           VAR_1->addr_mask + 1, VAR_2,

                           !(VAR_1->perm & IOMMU_WO) || mr->readonly);

        if (VAR_3) {

            error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx", %p) = %d (%m)",

                         container, iova,

                         VAR_1->addr_mask + 1, VAR_2, VAR_3);

        }

    } else {

        VAR_3 = vfio_dma_unmap(container, iova, VAR_1->addr_mask + 1);

        if (VAR_3) {

            error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "

                         "0x%"HWADDR_PRIx") = %d (%m)",

                         container, iova,

                         VAR_1->addr_mask + 1, VAR_3);

        }

    }

out:

    rcu_read_unlock();

}

static void FUNC_0(IOMMUNotifier *VAR_0, IOMMUTLBEntry *VAR_1)
{ VFIOGuestIOMMU *giommu = container_of(VAR_0, VFIOGuestIOMMU, VAR_0); VFIOContainer *container = giommu->container; hwaddr iova = VAR_1->iova + giommu->iommu_offset; MemoryRegion *mr; hwaddr xlat; hwaddr len = VAR_1->addr_mask + 1; void *VAR_2; int VAR_3; trace_vfio_iommu_map_notify(VAR_1->perm == IOMMU_NONE ? "UNMAP" : "MAP",
iova, iova + VAR_1->addr_mask); if (VAR_1->target_as != &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowed",
VAR_1->target_as->name ? VAR_1->target_as->name : "none"); return; } rcu_read_lock(); mr = address_space_translate(&address_space_memory,
VAR_1->translated_addr,
&xlat, &len, VAR_1->perm & IOMMU_WO); if (!memory_region_is_ram(mr)) { error_report("iommu map to non memory area %"HWADDR_PRIx"",
xlat); goto out; } if (len & VAR_1->addr_mask) { error_report("iommu has granularity incompatible with target AS"); goto out; } if ((VAR_1->perm & IOMMU_RW) != IOMMU_NONE) { VAR_2 = memory_region_get_ram_ptr(mr) + xlat; VAR_3 = vfio_dma_map(container, iova,
VAR_1->addr_mask + 1, VAR_2,
!(VAR_1->perm & IOMMU_WO) || mr->readonly); if (VAR_3) { error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", "
"0x%"HWADDR_PRIx", %p) = %d (%m)",
container, iova,
VAR_1->addr_mask + 1, VAR_2, VAR_3); } } else { VAR_3 = vfio_dma_unmap(container, iova, VAR_1->addr_mask + 1); if (VAR_3) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "
"0x%"HWADDR_PRIx") = %d (%m)",
container, iova,
VAR_1->addr_mask + 1, VAR_3); } } out:
rcu_read_unlock(); }