static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error **errp)

{

    sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(dev);

    int ret;



    if (nvram->blk) {

        nvram->size = blk_getlength(nvram->blk);



        ret = blk_set_perm(nvram->blk,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,

                           BLK_PERM_ALL, errp);

        if (ret < 0) {

            return;

        }

    } else {

        nvram->size = DEFAULT_NVRAM_SIZE;

    }



    nvram->buf = g_malloc0(nvram->size);



    if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {

        error_setg(errp, "spapr-nvram must be between %d and %d bytes in size",

                   MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);

        return;

    }



    if (nvram->blk) {

        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);



        if (alen != nvram->size) {

            error_setg(errp, "can't read spapr-nvram contents");

            return;

        }

    } else if (nb_prom_envs > 0) {

        /* Create a system partition to pass the -prom-env variables */

        chrp_nvram_create_system_partition(nvram->buf, MIN_NVRAM_SIZE / 4);

        chrp_nvram_create_free_partition(&nvram->buf[MIN_NVRAM_SIZE / 4],

                                         nvram->size - MIN_NVRAM_SIZE / 4);

    }



    spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch);

    spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store);

}

static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error **errp)

{

    sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(dev);

    int ret;



    if (nvram->blk) {

        nvram->size = blk_getlength(nvram->blk);



        ret = blk_set_perm(nvram->blk,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,

                           BLK_PERM_ALL, errp);

        if (ret < 0) {

            return;

        }

    } else {

        nvram->size = DEFAULT_NVRAM_SIZE;

    }



    nvram->buf = g_malloc0(nvram->size);



    if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {

        error_setg(errp, "spapr-nvram must be between %d and %d bytes in size",

                   MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);

        return;

    }



    if (nvram->blk) {

        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);



        if (alen != nvram->size) {

            error_setg(errp, "can't read spapr-nvram contents");

            return;

        }

    } else if (nb_prom_envs > 0) {

        

        chrp_nvram_create_system_partition(nvram->buf, MIN_NVRAM_SIZE / 4);

        chrp_nvram_create_free_partition(&nvram->buf[MIN_NVRAM_SIZE / 4],

                                         nvram->size - MIN_NVRAM_SIZE / 4);

    }



    spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch);

    spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store);

}

static void FUNC_0(VIOsPAPRDevice *VAR_0, Error **VAR_1)

{

    sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(VAR_0);

    int VAR_2;



    if (nvram->blk) {

        nvram->size = blk_getlength(nvram->blk);



        VAR_2 = blk_set_perm(nvram->blk,

                           BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,

                           BLK_PERM_ALL, VAR_1);

        if (VAR_2 < 0) {

            return;

        }

    } else {

        nvram->size = DEFAULT_NVRAM_SIZE;

    }



    nvram->buf = g_malloc0(nvram->size);



    if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) {

        error_setg(VAR_1, "spapr-nvram must be between %d and %d bytes in size",

                   MIN_NVRAM_SIZE, MAX_NVRAM_SIZE);

        return;

    }



    if (nvram->blk) {

        int VAR_3 = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);



        if (VAR_3 != nvram->size) {

            error_setg(VAR_1, "can't read spapr-nvram contents");

            return;

        }

    } else if (nb_prom_envs > 0) {

        

        chrp_nvram_create_system_partition(nvram->buf, MIN_NVRAM_SIZE / 4);

        chrp_nvram_create_free_partition(&nvram->buf[MIN_NVRAM_SIZE / 4],

                                         nvram->size - MIN_NVRAM_SIZE / 4);

    }



    spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch);

    spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store);

}

static void FUNC_0(VIOsPAPRDevice *VAR_0, Error **VAR_1)
{ sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(VAR_0); int VAR_2; if (nvram->blk) { nvram->size = blk_getlength(nvram->blk); VAR_2 = blk_set_perm(nvram->blk,
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
BLK_PERM_ALL, VAR_1); if (VAR_2 < 0) { return; } } else { nvram->size = DEFAULT_NVRAM_SIZE; } nvram->buf = g_malloc0(nvram->size); if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) { error_setg(VAR_1, "spapr-nvram must be between %d and %d bytes in size",
MIN_NVRAM_SIZE, MAX_NVRAM_SIZE); return; } if (nvram->blk) { int VAR_3 = blk_pread(nvram->blk, 0, nvram->buf, nvram->size); if (VAR_3 != nvram->size) { error_setg(VAR_1, "can't read spapr-nvram contents"); return; } } else if (nb_prom_envs > 0) { chrp_nvram_create_system_partition(nvram->buf, MIN_NVRAM_SIZE / 4); chrp_nvram_create_free_partition(&nvram->buf[MIN_NVRAM_SIZE / 4],
nvram->size - MIN_NVRAM_SIZE / 4); } spapr_rtas_register(RTAS_NVRAM_FETCH, "nvram-fetch", rtas_nvram_fetch); spapr_rtas_register(RTAS_NVRAM_STORE, "nvram-store", rtas_nvram_store); }