void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd,

                              bool vfio_accel)

{

    struct kvm_create_spapr_tce args = {

        .liobn = liobn,

        .window_size = window_size,

    };

    long len;

    int fd;

    void *table;



    /* Must set fd to -1 so we don't try to munmap when called for

     * destroying the table, which the upper layers -will- do

     */

    *pfd = -1;

    if (!cap_spapr_tce || (vfio_accel && !cap_spapr_vfio)) {

        return NULL;

    }



    fd = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &args);

    if (fd < 0) {

        fprintf(stderr, "KVM: Failed to create TCE table for liobn 0x%x\n",

                liobn);

        return NULL;

    }



    len = (window_size / SPAPR_TCE_PAGE_SIZE) * sizeof(uint64_t);

    /* FIXME: round this up to page size */



    table = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    if (table == MAP_FAILED) {

        fprintf(stderr, "KVM: Failed to map TCE table for liobn 0x%x\n",

                liobn);

        close(fd);

        return NULL;

    }



    *pfd = fd;

    return table;

}

void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd,

                              bool vfio_accel)

{

    struct kvm_create_spapr_tce args = {

        .liobn = liobn,

        .window_size = window_size,

    };

    long len;

    int fd;

    void *table;



    





    *pfd = -1;

    if (!cap_spapr_tce || (vfio_accel && !cap_spapr_vfio)) {

        return NULL;

    }



    fd = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &args);

    if (fd < 0) {

        fprintf(stderr, "KVM: Failed to create TCE table for liobn 0x%x\n",

                liobn);

        return NULL;

    }



    len = (window_size / SPAPR_TCE_PAGE_SIZE) * sizeof(uint64_t);

    



    table = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    if (table == MAP_FAILED) {

        fprintf(stderr, "KVM: Failed to map TCE table for liobn 0x%x\n",

                liobn);

        close(fd);

        return NULL;

    }



    *pfd = fd;

    return table;

}

void *FUNC_0(uint32_t VAR_0, uint32_t VAR_1, int *VAR_2,

                              bool VAR_3)

{

    struct kvm_create_spapr_tce VAR_4 = {

        .VAR_0 = VAR_0,

        .VAR_1 = VAR_1,

    };

    long VAR_5;

    int VAR_6;

    void *VAR_7;



    





    *VAR_2 = -1;

    if (!cap_spapr_tce || (VAR_3 && !cap_spapr_vfio)) {

        return NULL;

    }



    VAR_6 = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &VAR_4);

    if (VAR_6 < 0) {

        fprintf(stderr, "KVM: Failed to create TCE VAR_7 for VAR_0 0x%x\n",

                VAR_0);

        return NULL;

    }



    VAR_5 = (VAR_1 / SPAPR_TCE_PAGE_SIZE) * sizeof(uint64_t);

    



    VAR_7 = mmap(NULL, VAR_5, PROT_READ|PROT_WRITE, MAP_SHARED, VAR_6, 0);

    if (VAR_7 == MAP_FAILED) {

        fprintf(stderr, "KVM: Failed to map TCE VAR_7 for VAR_0 0x%x\n",

                VAR_0);

        close(VAR_6);

        return NULL;

    }



    *VAR_2 = VAR_6;

    return VAR_7;

}

void *FUNC_0(uint32_t VAR_0, uint32_t VAR_1, int *VAR_2,
bool VAR_3)
{ struct kvm_create_spapr_tce VAR_4 = { .VAR_0 = VAR_0,
.VAR_1 = VAR_1,
}; long VAR_5; int VAR_6; void *VAR_7; *VAR_2 = -1; if (!cap_spapr_tce || (VAR_3 && !cap_spapr_vfio)) { return NULL; } VAR_6 = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &VAR_4); if (VAR_6 < 0) { fprintf(stderr, "KVM: Failed to create TCE VAR_7 for VAR_0 0x%x\n",
VAR_0); return NULL; } VAR_5 = (VAR_1 / SPAPR_TCE_PAGE_SIZE) * sizeof(uint64_t); VAR_7 = mmap(NULL, VAR_5, PROT_READ|PROT_WRITE, MAP_SHARED, VAR_6, 0); if (VAR_7 == MAP_FAILED) { fprintf(stderr, "KVM: Failed to map TCE VAR_7 for VAR_0 0x%x\n",
VAR_0); close(VAR_6); return NULL; } *VAR_2 = VAR_6; return VAR_7; }