From patchwork Fri Jul 25 06:52:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 373591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 66C931401F0 for ; Fri, 25 Jul 2014 16:56:57 +1000 (EST) Received: from localhost ([::1]:53291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XAZR1-000811-J5 for incoming@patchwork.ozlabs.org; Fri, 25 Jul 2014 02:56:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XAZON-0003Nm-4V for qemu-devel@nongnu.org; Fri, 25 Jul 2014 02:54:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XAZOH-0007NH-DT for qemu-devel@nongnu.org; Fri, 25 Jul 2014 02:54:11 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:51117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XAZOF-0007L5-VX for qemu-devel@nongnu.org; Fri, 25 Jul 2014 02:54:05 -0400 Received: from 172.24.2.119 (EHLO szxeml452-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXD43591; Fri, 25 Jul 2014 14:53:13 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml452-hub.china.huawei.com (10.82.67.195) with Microsoft SMTP Server id 14.3.158.1; Fri, 25 Jul 2014 14:53:05 +0800 From: To: Date: Fri, 25 Jul 2014 14:52:48 +0800 Message-ID: <1406271172-1192-4-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1406271172-1192-1-git-send-email-arei.gonglei@huawei.com> References: <1406271172-1192-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: peter.maydell@linaro.org, weidong.huang@huawei.com, mst@redhat.com, aik@ozlabs.ru, armbru@redhat.com, kraxel@redhat.com, dmitry@daynix.com, akong@redhat.com, agraf@suse.de, Gonglei , lersek@redhat.com, marcel.a@redhat.com, somlo@cmu.edu, luonengjun@huawei.com, peter.huangpeng@huawei.com, alex.williamson@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com, rth@twiddle.net, kwolf@redhat.com, peter.crosthwaite@xilinx.com, Chenliang , imammedo@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 3/7] fw_cfg: add fw_cfg_machine_reset function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei We must assure that the changed bootindex can take effect when guest is rebooted. So we introduce fw_cfg_machine_reset(), which change the fw_cfg file's bootindex data using the new global fw_boot_order list. Signed-off-by: Chenliang Signed-off-by: Gonglei --- hw/nvram/fw_cfg.c | 54 +++++++++++++++++++++++++++++++++++++++++------ include/hw/nvram/fw_cfg.h | 2 ++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index b71d251..a24a44d 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -56,7 +56,6 @@ struct FWCfgState { FWCfgFiles *files; uint16_t cur_entry; uint32_t cur_offset; - Notifier machine_ready; }; #define JPG_FILE 0 @@ -402,6 +401,26 @@ static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key, s->entries[arch][key].callback_opaque = callback_opaque; } +static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key, + void *data, size_t len) +{ + void *ptr; + int arch = !!(key & FW_CFG_ARCH_LOCAL); + + key &= FW_CFG_ENTRY_MASK; + + assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX); + + /* return the old data to the function caller, avoid memory leak */ + ptr = s->entries[arch][key].data; + s->entries[arch][key].data = data; + s->entries[arch][key].len = len; + s->entries[arch][key].callback_opaque = NULL; + s->entries[arch][key].callback = NULL; + + return ptr; +} + void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len) { fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len); @@ -499,13 +518,36 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len); } -static void fw_cfg_machine_ready(struct Notifier *n, void *data) +void *fw_cfg_modify_file(FWCfgState *s, const char *filename, + void *data, size_t len) +{ + int i, index; + + assert(s->files); + + index = be32_to_cpu(s->files->count); + assert(index < FW_CFG_FILE_SLOTS); + + for (i = 0; i < index; i++) { + if (strcmp(filename, s->files->f[i].name) == 0) { + return fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i, + data, len); + } + } + /* add new one */ + fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len); + return NULL; +} + +static void fw_cfg_machine_reset(void *opaque) { + void *ptr; size_t len; - FWCfgState *s = container_of(n, FWCfgState, machine_ready); + FWCfgState *s = opaque; char *bootindex = get_boot_devices_list(&len, false); - fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len); + ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)bootindex, len); + g_free(ptr); } FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, @@ -542,9 +584,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, fw_cfg_bootsplash(s); fw_cfg_reboot(s); - s->machine_ready.notify = fw_cfg_machine_ready; - qemu_add_machine_init_done_notifier(&s->machine_ready); - + qemu_register_reset(fw_cfg_machine_reset, s); return s; } diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 72b1549..56e1ed7 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -76,6 +76,8 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, FWCfgReadCallback callback, void *callback_opaque, void *data, size_t len); +void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, + size_t len); FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, hwaddr crl_addr, hwaddr data_addr);