static void spapr_finalize_fdt(sPAPRMachineState *spapr,

                               hwaddr fdt_addr,

                               hwaddr rtas_addr,

                               hwaddr rtas_size)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    const char *boot_device = machine->boot_order;

    int ret, i;

    size_t cb = 0;

    char *bootlist;

    void *fdt;

    sPAPRPHBState *phb;



    fdt = g_malloc(FDT_MAX_SIZE);



    /* open out the base tree into a temp buffer for the final tweaks */

    _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));



    ret = spapr_populate_memory(spapr, fdt);

    if (ret < 0) {

        fprintf(stderr, "couldn't setup memory nodes in fdt\n");

        exit(1);

    }



    ret = spapr_populate_vdevice(spapr->vio_bus, fdt);

    if (ret < 0) {

        fprintf(stderr, "couldn't setup vio devices in fdt\n");

        exit(1);

    }



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

        ret = spapr_rng_populate_dt(fdt);

        if (ret < 0) {

            fprintf(stderr, "could not set up rng device in the fdt\n");

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

        }

    }



    /* RTAS */

    ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size);

    if (ret < 0) {

        fprintf(stderr, "Couldn't set up RTAS device tree properties\n");

    }



    /* cpus */

    spapr_populate_cpus_dt_node(fdt, spapr);



    bootlist = get_boot_devices_list(&cb, true);

    if (cb && bootlist) {

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

        if (offset < 0) {

            exit(1);

        }

        for (i = 0; i < cb; i++) {

            if (bootlist[i] == '\n') {

                bootlist[i] = ' ';

            }



        }

        ret = fdt_setprop_string(fdt, offset, "qemu,boot-list", bootlist);

    }



    if (boot_device && strlen(boot_device)) {

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



        if (offset < 0) {

            exit(1);

        }

        fdt_setprop_string(fdt, offset, "qemu,boot-device", boot_device);

    }



    if (!spapr->has_graphics) {

        spapr_populate_chosen_stdout(fdt, spapr->vio_bus);

    }



    if (smc->dr_lmb_enabled) {

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

    }



    if (smc->dr_cpu_enabled) {

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

        }

    }



    _FDT((fdt_pack(fdt)));



    if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {

        error_report("FDT too big ! 0x%x bytes (max is 0x%x)",

                     fdt_totalsize(fdt), FDT_MAX_SIZE);

        exit(1);

    }



    qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));

    cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));



    g_free(bootlist);

    g_free(fdt);

}

static void spapr_finalize_fdt(sPAPRMachineState *spapr,

                               hwaddr fdt_addr,

                               hwaddr rtas_addr,

                               hwaddr rtas_size)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    const char *boot_device = machine->boot_order;

    int ret, i;

    size_t cb = 0;

    char *bootlist;

    void *fdt;

    sPAPRPHBState *phb;



    fdt = g_malloc(FDT_MAX_SIZE);



    

    _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));



    ret = spapr_populate_memory(spapr, fdt);

    if (ret < 0) {

        fprintf(stderr, "couldn't setup memory nodes in fdt\n");

        exit(1);

    }



    ret = spapr_populate_vdevice(spapr->vio_bus, fdt);

    if (ret < 0) {

        fprintf(stderr, "couldn't setup vio devices in fdt\n");

        exit(1);

    }



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

        ret = spapr_rng_populate_dt(fdt);

        if (ret < 0) {

            fprintf(stderr, "could not set up rng device in the fdt\n");

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

        }

    }



    

    ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size);

    if (ret < 0) {

        fprintf(stderr, "Couldn't set up RTAS device tree properties\n");

    }



    

    spapr_populate_cpus_dt_node(fdt, spapr);



    bootlist = get_boot_devices_list(&cb, true);

    if (cb && bootlist) {

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

        if (offset < 0) {

            exit(1);

        }

        for (i = 0; i < cb; i++) {

            if (bootlist[i] == '\n') {

                bootlist[i] = ' ';

            }



        }

        ret = fdt_setprop_string(fdt, offset, "qemu,boot-list", bootlist);

    }



    if (boot_device && strlen(boot_device)) {

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



        if (offset < 0) {

            exit(1);

        }

        fdt_setprop_string(fdt, offset, "qemu,boot-device", boot_device);

    }



    if (!spapr->has_graphics) {

        spapr_populate_chosen_stdout(fdt, spapr->vio_bus);

    }



    if (smc->dr_lmb_enabled) {

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

    }



    if (smc->dr_cpu_enabled) {

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

        }

    }



    _FDT((fdt_pack(fdt)));



    if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {

        error_report("FDT too big ! 0x%x bytes (max is 0x%x)",

                     fdt_totalsize(fdt), FDT_MAX_SIZE);

        exit(1);

    }



    qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));

    cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));



    g_free(bootlist);

    g_free(fdt);

}

    if (smc->dr_cpu_enabled) {     if (smc->dr_cpu_enabled) {     if (smc->dr_cpu_enabled) {     sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);     if (smc->dr_cpu_enabled) {
static void FUNC_0(sPAPRMachineState *VAR_0,

                               hwaddr VAR_1,

                               hwaddr VAR_2,

                               hwaddr VAR_3)

{

    MachineState *machine = MACHINE(qdev_get_machine());

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);

    const char *VAR_4 = machine->boot_order;

    int VAR_5, VAR_6;

    size_t cb = 0;

    char *VAR_7;

    void *VAR_8;

    sPAPRPHBState *phb;



    VAR_8 = g_malloc(FDT_MAX_SIZE);



    

    _FDT((fdt_open_into(VAR_0->fdt_skel, VAR_8, FDT_MAX_SIZE)));



    VAR_5 = spapr_populate_memory(VAR_0, VAR_8);

    if (VAR_5 < 0) {

        fprintf(stderr, "couldn't setup memory nodes in VAR_8\n");

        exit(1);

    }



    VAR_5 = spapr_populate_vdevice(VAR_0->vio_bus, VAR_8);

    if (VAR_5 < 0) {

        fprintf(stderr, "couldn't setup vio devices in VAR_8\n");

        exit(1);

    }



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

        VAR_5 = spapr_rng_populate_dt(VAR_8);

        if (VAR_5 < 0) {

            fprintf(stderr, "could not set up rng device in the VAR_8\n");

            exit(1);

        }

    }



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

        VAR_5 = spapr_populate_pci_dt(phb, PHANDLE_XICP, VAR_8);

        if (VAR_5 < 0) {

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

            exit(1);

        }

    }



    

    VAR_5 = spapr_rtas_device_tree_setup(VAR_8, VAR_2, VAR_3);

    if (VAR_5 < 0) {

        fprintf(stderr, "Couldn't set up RTAS device tree properties\n");

    }



    

    spapr_populate_cpus_dt_node(VAR_8, VAR_0);



    VAR_7 = get_boot_devices_list(&cb, true);

    if (cb && VAR_7) {

        int VAR_10 = fdt_path_offset(VAR_8, "/chosen");

        if (VAR_10 < 0) {

            exit(1);

        }

        for (VAR_6 = 0; VAR_6 < cb; VAR_6++) {

            if (VAR_7[VAR_6] == '\n') {

                VAR_7[VAR_6] = ' ';

            }



        }

        VAR_5 = fdt_setprop_string(VAR_8, VAR_10, "qemu,boot-list", VAR_7);

    }



    if (VAR_4 && strlen(VAR_4)) {

        int VAR_10 = fdt_path_offset(VAR_8, "/chosen");



        if (VAR_10 < 0) {

            exit(1);

        }

        fdt_setprop_string(VAR_8, VAR_10, "qemu,boot-device", VAR_4);

    }



    if (!VAR_0->has_graphics) {

        spapr_populate_chosen_stdout(VAR_8, VAR_0->vio_bus);

    }



    if (smc->dr_lmb_enabled) {

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

    }



    if (smc->dr_cpu_enabled) {

        int VAR_10 = fdt_path_offset(VAR_8, "/cpus");

        VAR_5 = spapr_drc_populate_dt(VAR_8, VAR_10, NULL,

                                    SPAPR_DR_CONNECTOR_TYPE_CPU);

        if (VAR_5 < 0) {

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

            exit(1);

        }

    }



    _FDT((fdt_pack(VAR_8)));



    if (fdt_totalsize(VAR_8) > FDT_MAX_SIZE) {

        error_report("FDT too big ! 0x%x bytes (max is 0x%x)",

                     fdt_totalsize(VAR_8), FDT_MAX_SIZE);

        exit(1);

    }



    qemu_fdt_dumpdtb(VAR_8, fdt_totalsize(VAR_8));

    cpu_physical_memory_write(VAR_1, VAR_8, fdt_totalsize(VAR_8));



    g_free(VAR_7);

    g_free(VAR_8);

}

static void FUNC_0(sPAPRMachineState *VAR_0,
hwaddr VAR_1,
hwaddr VAR_2,
hwaddr VAR_3)
{ MachineState *machine = MACHINE(qdev_get_machine()); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine); const char *VAR_4 = machine->boot_order; int VAR_5, VAR_6; size_t cb = 0; char *VAR_7; void *VAR_8; sPAPRPHBState *phb; VAR_8 = g_malloc(FDT_MAX_SIZE); _FDT((fdt_open_into(VAR_0->fdt_skel, VAR_8, FDT_MAX_SIZE))); VAR_5 = spapr_populate_memory(VAR_0, VAR_8); if (VAR_5 < 0) { fprintf(stderr, "couldn't setup memory nodes in VAR_8\n"); exit(1); } VAR_5 = spapr_populate_vdevice(VAR_0->vio_bus, VAR_8); if (VAR_5 < 0) { fprintf(stderr, "couldn't setup vio devices in VAR_8\n"); exit(1); } if (object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) { VAR_5 = spapr_rng_populate_dt(VAR_8); if (VAR_5 < 0) { fprintf(stderr, "could not set up rng device in the VAR_8\n"); exit(1); } } QLIST_FOREACH(phb, &VAR_0->phbs, list) { VAR_5 = spapr_populate_pci_dt(phb, PHANDLE_XICP, VAR_8); if (VAR_5 < 0) { error_report("couldn't setup PCI devices in VAR_8"); exit(1); } } VAR_5 = spapr_rtas_device_tree_setup(VAR_8, VAR_2, VAR_3); if (VAR_5 < 0) { fprintf(stderr, "Couldn't set up RTAS device tree properties\n"); } spapr_populate_cpus_dt_node(VAR_8, VAR_0); VAR_7 = get_boot_devices_list(&cb, true); if (cb && VAR_7) { int VAR_10 = fdt_path_offset(VAR_8, "/chosen"); if (VAR_10 < 0) { exit(1); } for (VAR_6 = 0; VAR_6 < cb; VAR_6++) { if (VAR_7[VAR_6] == '\n') { VAR_7[VAR_6] = ' '; } } VAR_5 = fdt_setprop_string(VAR_8, VAR_10, "qemu,boot-list", VAR_7); } if (VAR_4 && strlen(VAR_4)) { int VAR_10 = fdt_path_offset(VAR_8, "/chosen"); if (VAR_10 < 0) { exit(1); } fdt_setprop_string(VAR_8, VAR_10, "qemu,boot-device", VAR_4); } if (!VAR_0->has_graphics) { spapr_populate_chosen_stdout(VAR_8, VAR_0->vio_bus); } if (smc->dr_lmb_enabled) { _FDT(spapr_drc_populate_dt(VAR_8, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB)); } if (smc->dr_cpu_enabled) { int VAR_10 = fdt_path_offset(VAR_8, "/cpus"); VAR_5 = spapr_drc_populate_dt(VAR_8, VAR_10, NULL,
SPAPR_DR_CONNECTOR_TYPE_CPU); if (VAR_5 < 0) { error_report("Couldn't set up CPU DR device tree properties"); exit(1); } } _FDT((fdt_pack(VAR_8))); if (fdt_totalsize(VAR_8) > FDT_MAX_SIZE) { error_report("FDT too big ! 0x%x bytes (max is 0x%x)",
fdt_totalsize(VAR_8), FDT_MAX_SIZE); exit(1); } qemu_fdt_dumpdtb(VAR_8, fdt_totalsize(VAR_8)); cpu_physical_memory_write(VAR_1, VAR_8, fdt_totalsize(VAR_8)); g_free(VAR_7); g_free(VAR_8); }