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

{

    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) {

        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(sPAPRTCE);

    /* 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)

{

    struct kvm_create_spapr_tce args = {

        .liobn = liobn,

        .window_size = window_size,

    };

    long len;

    int fd;

    void *table;



    





    *pfd = -1;

    if (!cap_spapr_tce) {

        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(sPAPRTCE);

    



    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)

{

    struct kvm_create_spapr_tce VAR_3 = {

        .VAR_0 = VAR_0,

        .VAR_1 = VAR_1,

    };

    long VAR_4;

    int VAR_5;

    void *VAR_6;



    





    *VAR_2 = -1;

    if (!cap_spapr_tce) {

        return NULL;

    }



    VAR_5 = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE, &VAR_3);

    if (VAR_5 < 0) {

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

                VAR_0);

        return NULL;

    }



    VAR_4 = (VAR_1 / SPAPR_TCE_PAGE_SIZE) * sizeof(sPAPRTCE);

    



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

    if (VAR_6 == MAP_FAILED) {

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

                VAR_0);

        close(VAR_5);

        return NULL;

    }



    *VAR_2 = VAR_5;

    return VAR_6;

}

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