static void *spapr_build_fdt(sPAPRMachineState *spapr,

                             hwaddr rtas_addr,

                             hwaddr rtas_size)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(machine);

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    int ret;

    void *fdt;

    sPAPRPHBState *phb;

    char *buf;



    fdt = g_malloc0(FDT_MAX_SIZE);

    _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE)));



    /* Root node */

    _FDT(fdt_setprop_string(fdt, 0, "device_type", "chrp"));

    _FDT(fdt_setprop_string(fdt, 0, "model", "IBM pSeries (emulated by qemu)"));

    _FDT(fdt_setprop_string(fdt, 0, "compatible", "qemu,pseries"));



    /*

     * Add info to guest to indentify which host is it being run on

     * and what is the uuid of the guest

     */

    if (kvmppc_get_host_model(&buf)) {

        _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));

        g_free(buf);

    }

    if (kvmppc_get_host_serial(&buf)) {

        _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));

        g_free(buf);

    }



    buf = qemu_uuid_unparse_strdup(&qemu_uuid);



    _FDT(fdt_setprop_string(fdt, 0, "vm,uuid", buf));

    if (qemu_uuid_set) {

        _FDT(fdt_setprop_string(fdt, 0, "system-id", buf));

    }

    g_free(buf);



    if (qemu_get_vm_name()) {

        _FDT(fdt_setprop_string(fdt, 0, "ibm,partition-name",

                                qemu_get_vm_name()));

    }



    _FDT(fdt_setprop_cell(fdt, 0, "#address-cells", 2));

    _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2));



    /* /interrupt controller */

    spapr_dt_xics(spapr->xics, fdt, PHANDLE_XICP);



    ret = spapr_populate_memory(spapr, fdt);

    if (ret < 0) {

        error_report("couldn't setup memory nodes in fdt");

        exit(1);

    }



    /* /vdevice */

    spapr_dt_vdevice(spapr->vio_bus, fdt);



    if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) {

        ret = spapr_rng_populate_dt(fdt);

        if (ret < 0) {

            error_report("could not set up rng device in the fdt");

            exit(1);

        }

    }



    QLIST_FOREACH(phb, &spapr->phbs, list) {

        ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);

        if (ret < 0) {

            error_report("couldn't setup PCI devices in fdt");

            exit(1);

        }

    }



    /* cpus */

    spapr_populate_cpus_dt_node(fdt, spapr);



    if (smc->dr_lmb_enabled) {

        _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));

    }



    if (mc->query_hotpluggable_cpus) {

        int offset = fdt_path_offset(fdt, "/cpus");

        ret = spapr_drc_populate_dt(fdt, offset, NULL,

                                    SPAPR_DR_CONNECTOR_TYPE_CPU);

        if (ret < 0) {

            error_report("Couldn't set up CPU DR device tree properties");

            exit(1);

        }

    }



    /* /event-sources */

    spapr_dt_events(fdt, spapr->check_exception_irq);



    /* /rtas */

    spapr_dt_rtas(spapr, fdt);



    /* /chosen */

    spapr_dt_chosen(spapr, fdt);



    /* /hypervisor */

    if (kvm_enabled()) {

        spapr_dt_hypervisor(spapr, fdt);

    }



    /* Build memory reserve map */

    if (spapr->kernel_size) {

        _FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_size)));

    }

    if (spapr->initrd_size) {

        _FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, spapr->initrd_size)));

    }



    /* ibm,client-architecture-support updates */

    ret = spapr_dt_cas_updates(spapr, fdt, spapr->ov5_cas);

    if (ret < 0) {

        error_report("couldn't setup CAS properties fdt");

        exit(1);

    }



    return fdt;

}

static void *spapr_build_fdt(sPAPRMachineState *spapr,

                             hwaddr rtas_addr,

                             hwaddr rtas_size)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(machine);

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    int ret;

    void *fdt;

    sPAPRPHBState *phb;

    char *buf;



    fdt = g_malloc0(FDT_MAX_SIZE);

    _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE)));



    

    _FDT(fdt_setprop_string(fdt, 0, "device_type", "chrp"));

    _FDT(fdt_setprop_string(fdt, 0, "model", "IBM pSeries (emulated by qemu)"));

    _FDT(fdt_setprop_string(fdt, 0, "compatible", "qemu,pseries"));



    







    if (kvmppc_get_host_model(&buf)) {

        _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));

        g_free(buf);

    }

    if (kvmppc_get_host_serial(&buf)) {

        _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));

        g_free(buf);

    }



    buf = qemu_uuid_unparse_strdup(&qemu_uuid);



    _FDT(fdt_setprop_string(fdt, 0, "vm,uuid", buf));

    if (qemu_uuid_set) {

        _FDT(fdt_setprop_string(fdt, 0, "system-id", buf));

    }

    g_free(buf);



    if (qemu_get_vm_name()) {

        _FDT(fdt_setprop_string(fdt, 0, "ibm,partition-name",

                                qemu_get_vm_name()));

    }



    _FDT(fdt_setprop_cell(fdt, 0, "#address-cells", 2));

    _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2));



    

    spapr_dt_xics(spapr->xics, fdt, PHANDLE_XICP);



    ret = spapr_populate_memory(spapr, fdt);

    if (ret < 0) {

        error_report("couldn't setup memory nodes in fdt");

        exit(1);

    }



    

    spapr_dt_vdevice(spapr->vio_bus, fdt);



    if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) {

        ret = spapr_rng_populate_dt(fdt);

        if (ret < 0) {

            error_report("could not set up rng device in the fdt");

            exit(1);

        }

    }



    QLIST_FOREACH(phb, &spapr->phbs, list) {

        ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);

        if (ret < 0) {

            error_report("couldn't setup PCI devices in fdt");

            exit(1);

        }

    }



    

    spapr_populate_cpus_dt_node(fdt, spapr);



    if (smc->dr_lmb_enabled) {

        _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));

    }



    if (mc->query_hotpluggable_cpus) {

        int offset = fdt_path_offset(fdt, "/cpus");

        ret = spapr_drc_populate_dt(fdt, offset, NULL,

                                    SPAPR_DR_CONNECTOR_TYPE_CPU);

        if (ret < 0) {

            error_report("Couldn't set up CPU DR device tree properties");

            exit(1);

        }

    }



    

    spapr_dt_events(fdt, spapr->check_exception_irq);



    

    spapr_dt_rtas(spapr, fdt);



    

    spapr_dt_chosen(spapr, fdt);



    

    if (kvm_enabled()) {

        spapr_dt_hypervisor(spapr, fdt);

    }



    

    if (spapr->kernel_size) {

        _FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_size)));

    }

    if (spapr->initrd_size) {

        _FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, spapr->initrd_size)));

    }



    

    ret = spapr_dt_cas_updates(spapr, fdt, spapr->ov5_cas);

    if (ret < 0) {

        error_report("couldn't setup CAS properties fdt");

        exit(1);

    }



    return fdt;

}

static void *FUNC_0(sPAPRMachineState *VAR_0,

                             hwaddr VAR_1,

                             hwaddr VAR_2)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    MachineClass *mc = MACHINE_GET_CLASS(machine);

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    int VAR_3;

    void *VAR_4;

    sPAPRPHBState *phb;

    char *VAR_5;



    VAR_4 = g_malloc0(FDT_MAX_SIZE);

    _FDT((fdt_create_empty_tree(VAR_4, FDT_MAX_SIZE)));



    

    _FDT(fdt_setprop_string(VAR_4, 0, "device_type", "chrp"));

    _FDT(fdt_setprop_string(VAR_4, 0, "model", "IBM pSeries (emulated by qemu)"));

    _FDT(fdt_setprop_string(VAR_4, 0, "compatible", "qemu,pseries"));



    







    if (kvmppc_get_host_model(&VAR_5)) {

        _FDT(fdt_setprop_string(VAR_4, 0, "host-model", VAR_5));

        g_free(VAR_5);

    }

    if (kvmppc_get_host_serial(&VAR_5)) {

        _FDT(fdt_setprop_string(VAR_4, 0, "host-serial", VAR_5));

        g_free(VAR_5);

    }



    VAR_5 = qemu_uuid_unparse_strdup(&qemu_uuid);



    _FDT(fdt_setprop_string(VAR_4, 0, "vm,uuid", VAR_5));

    if (qemu_uuid_set) {

        _FDT(fdt_setprop_string(VAR_4, 0, "system-id", VAR_5));

    }

    g_free(VAR_5);



    if (qemu_get_vm_name()) {

        _FDT(fdt_setprop_string(VAR_4, 0, "ibm,partition-name",

                                qemu_get_vm_name()));

    }



    _FDT(fdt_setprop_cell(VAR_4, 0, "#address-cells", 2));

    _FDT(fdt_setprop_cell(VAR_4, 0, "#size-cells", 2));



    

    spapr_dt_xics(VAR_0->xics, VAR_4, PHANDLE_XICP);



    VAR_3 = spapr_populate_memory(VAR_0, VAR_4);

    if (VAR_3 < 0) {

        error_report("couldn't setup memory nodes in VAR_4");

        exit(1);

    }



    

    spapr_dt_vdevice(VAR_0->vio_bus, VAR_4);



    if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) {

        VAR_3 = spapr_rng_populate_dt(VAR_4);

        if (VAR_3 < 0) {

            error_report("could not set up rng device in the VAR_4");

            exit(1);

        }

    }



    QLIST_FOREACH(phb, &VAR_0->phbs, list) {

        VAR_3 = spapr_populate_pci_dt(phb, PHANDLE_XICP, VAR_4);

        if (VAR_3 < 0) {

            error_report("couldn't setup PCI devices in VAR_4");

            exit(1);

        }

    }



    

    spapr_populate_cpus_dt_node(VAR_4, VAR_0);



    if (smc->dr_lmb_enabled) {

        _FDT(spapr_drc_populate_dt(VAR_4, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));

    }



    if (mc->query_hotpluggable_cpus) {

        int VAR_6 = fdt_path_offset(VAR_4, "/cpus");

        VAR_3 = spapr_drc_populate_dt(VAR_4, VAR_6, NULL,

                                    SPAPR_DR_CONNECTOR_TYPE_CPU);

        if (VAR_3 < 0) {

            error_report("Couldn't set up CPU DR device tree properties");

            exit(1);

        }

    }



    

    spapr_dt_events(VAR_4, VAR_0->check_exception_irq);



    

    spapr_dt_rtas(VAR_0, VAR_4);



    

    spapr_dt_chosen(VAR_0, VAR_4);



    

    if (kvm_enabled()) {

        spapr_dt_hypervisor(VAR_0, VAR_4);

    }



    

    if (VAR_0->kernel_size) {

        _FDT((fdt_add_mem_rsv(VAR_4, KERNEL_LOAD_ADDR, VAR_0->kernel_size)));

    }

    if (VAR_0->initrd_size) {

        _FDT((fdt_add_mem_rsv(VAR_4, VAR_0->initrd_base, VAR_0->initrd_size)));

    }



    

    VAR_3 = spapr_dt_cas_updates(VAR_0, VAR_4, VAR_0->ov5_cas);

    if (VAR_3 < 0) {

        error_report("couldn't setup CAS properties VAR_4");

        exit(1);

    }



    return VAR_4;

}

static void *FUNC_0(sPAPRMachineState *VAR_0,
hwaddr VAR_1,
hwaddr VAR_2)
{ MachineState *machine = MACHINE(qdev_get_machine()); MachineClass *mc = MACHINE_GET_CLASS(machine); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine); int VAR_3; void *VAR_4; sPAPRPHBState *phb; char *VAR_5; VAR_4 = g_malloc0(FDT_MAX_SIZE); _FDT((fdt_create_empty_tree(VAR_4, FDT_MAX_SIZE))); _FDT(fdt_setprop_string(VAR_4, 0, "device_type", "chrp")); _FDT(fdt_setprop_string(VAR_4, 0, "model", "IBM pSeries (emulated by qemu)")); _FDT(fdt_setprop_string(VAR_4, 0, "compatible", "qemu,pseries")); if (kvmppc_get_host_model(&VAR_5)) { _FDT(fdt_setprop_string(VAR_4, 0, "host-model", VAR_5)); g_free(VAR_5); } if (kvmppc_get_host_serial(&VAR_5)) { _FDT(fdt_setprop_string(VAR_4, 0, "host-serial", VAR_5)); g_free(VAR_5); } VAR_5 = qemu_uuid_unparse_strdup(&qemu_uuid); _FDT(fdt_setprop_string(VAR_4, 0, "vm,uuid", VAR_5)); if (qemu_uuid_set) { _FDT(fdt_setprop_string(VAR_4, 0, "system-id", VAR_5)); } g_free(VAR_5); if (qemu_get_vm_name()) { _FDT(fdt_setprop_string(VAR_4, 0, "ibm,partition-name",
qemu_get_vm_name())); } _FDT(fdt_setprop_cell(VAR_4, 0, "#address-cells", 2)); _FDT(fdt_setprop_cell(VAR_4, 0, "#size-cells", 2)); spapr_dt_xics(VAR_0->xics, VAR_4, PHANDLE_XICP); VAR_3 = spapr_populate_memory(VAR_0, VAR_4); if (VAR_3 < 0) { error_report("couldn't setup memory nodes in VAR_4"); exit(1); } spapr_dt_vdevice(VAR_0->vio_bus, VAR_4); if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) { VAR_3 = spapr_rng_populate_dt(VAR_4); if (VAR_3 < 0) { error_report("could not set up rng device in the VAR_4"); exit(1); } } QLIST_FOREACH(phb, &VAR_0->phbs, list) { VAR_3 = spapr_populate_pci_dt(phb, PHANDLE_XICP, VAR_4); if (VAR_3 < 0) { error_report("couldn't setup PCI devices in VAR_4"); exit(1); } } spapr_populate_cpus_dt_node(VAR_4, VAR_0); if (smc->dr_lmb_enabled) { _FDT(spapr_drc_populate_dt(VAR_4, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB)); } if (mc->query_hotpluggable_cpus) { int VAR_6 = fdt_path_offset(VAR_4, "/cpus"); VAR_3 = spapr_drc_populate_dt(VAR_4, VAR_6, NULL,
SPAPR_DR_CONNECTOR_TYPE_CPU); if (VAR_3 < 0) { error_report("Couldn't set up CPU DR device tree properties"); exit(1); } } spapr_dt_events(VAR_4, VAR_0->check_exception_irq); spapr_dt_rtas(VAR_0, VAR_4); spapr_dt_chosen(VAR_0, VAR_4); if (kvm_enabled()) { spapr_dt_hypervisor(VAR_0, VAR_4); } if (VAR_0->kernel_size) { _FDT((fdt_add_mem_rsv(VAR_4, KERNEL_LOAD_ADDR, VAR_0->kernel_size))); } if (VAR_0->initrd_size) { _FDT((fdt_add_mem_rsv(VAR_4, VAR_0->initrd_base, VAR_0->initrd_size))); } VAR_3 = spapr_dt_cas_updates(VAR_0, VAR_4, VAR_0->ov5_cas); if (VAR_3 < 0) { error_report("couldn't setup CAS properties VAR_4"); exit(1); } return VAR_4; }