From patchwork Wed Feb 20 13:59:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10822437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8894139A for ; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF4D2EEF5 for ; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D7EA2EF01; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9D6D2EEF5 for ; Wed, 20 Feb 2019 15:56:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:41431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUEJ-0001Ts-Jd for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:56:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTwH-0002KT-Kv for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTvv-000634-0T for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:27 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:37318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTvq-0004yZ-Ub for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:14 -0500 Received: by mail-ot1-x343.google.com with SMTP id b3so40817683otp.4 for ; Wed, 20 Feb 2019 07:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=Ot7Q8PKB6jEyjcT/kYdT3DXO9sInl/d71s7CEB0HMrunS/jjhxfyL6zaNGpRBgJt36 xFRefp8AXLbCVYnJ9Bfk/BriXw7ihp+rfm+uuX/p69tlgfe5lGyDtudMzNcTnM13+KdX Kplc0LeYQhl6z7+Kqm/RpXdlivjTY1a1ahuF8wT4EQ/51p8fTdHmL2Ttwsx54vtXsjKq WfQ+EVfKnt4cpr6Lw6reCe205pEdVSUKG5+3gFx+vzPZDRRlmXvniiDIhITOoMXa5069 UpxfuGufSMO0oH3ASr+x52ey7uHoYeBaZC9ZtoIhS2tRsijhiF0dT97d/kiX7s70tFcP hImA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=sJBDKMAdUf33yVQ26DkJw0fGuCjS9d+JLoKKGiQ4PbuMq9bwfiwAiES8PC6kXwaGS6 kSgZB0xs0uYoQPHBI4c4o4WbCz86XUXF43xP6uX7tAV8hZzE8O77qBzytZYgMitORll7 qSCTUeQE1IXWY2n3bPow+cplcyNgwtAOyWrkgTt8A+18NOxWe2glgRvginMmPvnKb52n b6rVsCkM0jSAYQLg+Y+uGzu/IYaXjcQ5E68owXosUNlJwxyxGnkU3FlJ9aonOe/gC4j6 GBZvrr0hJMsLOSOdmPxEIGomhR/270WrCF6HpDMtqC7S3Abw7uFjbo5stCyDEim+Gnjv OM8Q== X-Gm-Message-State: AHQUAuZY/JuEUfms45ZsQC63oMPqFsryKxssL02bUHHC34Fqg+JfyTPW kuwGNNI5yr6a0AXsKzBq/fSd4Wmo4Q== X-Google-Smtp-Source: AHgI3IbETGD0bTBkCqPfW5ihHgthAZvLOdKn1z2eLsTC7yTIj98fwHL84uKscUNsYI3jpV8mfc7KmA== X-Received: by 2002:aca:ad8f:: with SMTP id w137mr6171599oie.12.1550671216937; Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id i9sm1561125oth.13.2019.02.20.06.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 2D09D1808F8; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id E9279302A6C; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:50 -0600 Message-Id: <20190220135956.22589-14-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH 13/19] i2c:pm_smbus: Fix state transfer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard Transfer the state information for the SMBus registers and internal data so it will work on a VM transfer. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- hw/acpi/piix4.c | 7 +++++++ hw/i2c/pm_smbus.c | 31 +++++++++++++++++++++++++++++++ hw/i2c/smbus_ich9.c | 10 +++++++++- include/hw/i2c/pm_smbus.h | 9 +++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 88f9a9ec09..7f8efe9997 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -302,6 +302,11 @@ static const VMStateDescription vmstate_cpuhp_state = { } }; +static bool piix4_vmstate_need_smbus(void *opaque, int version_id) +{ + return pm_smbus_vmstate_needed(); +} + /* qemu-kvm 1.2 uses version 3 but advertised as 2 * To support incoming qemu-kvm 1.2 migration, change version_id * and minimum_version_id to 2 below (which breaks migration from @@ -321,6 +326,8 @@ static const VMStateDescription vmstate_acpi = { VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState), VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState), VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState), + VMSTATE_STRUCT_TEST(smb, PIIX4PMState, piix4_vmstate_need_smbus, 3, + pmsmb_vmstate, PMSMBus), VMSTATE_TIMER_PTR(ar.tmr.timer, PIIX4PMState), VMSTATE_INT64(ar.tmr.overflow_time, PIIX4PMState), VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE), diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 81d2a425ec..e48544f909 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" #include "hw/hw.h" +#include "hw/boards.h" #include "hw/i2c/pm_smbus.h" #include "hw/i2c/smbus_master.h" @@ -453,6 +454,36 @@ static const MemoryRegionOps pm_smbus_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; +bool pm_smbus_vmstate_needed(void) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + + return !mc->smbus_no_migration_support; +} + +const VMStateDescription pmsmb_vmstate = { + .name = "pmsmb", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(smb_stat, PMSMBus), + VMSTATE_UINT8(smb_ctl, PMSMBus), + VMSTATE_UINT8(smb_cmd, PMSMBus), + VMSTATE_UINT8(smb_addr, PMSMBus), + VMSTATE_UINT8(smb_data0, PMSMBus), + VMSTATE_UINT8(smb_data1, PMSMBus), + VMSTATE_UINT32(smb_index, PMSMBus), + VMSTATE_UINT8_ARRAY(smb_data, PMSMBus, PM_SMBUS_MAX_MSG_SIZE), + VMSTATE_UINT8(smb_auxctl, PMSMBus), + VMSTATE_UINT8(smb_blkdata, PMSMBus), + VMSTATE_BOOL(i2c_enable, PMSMBus), + VMSTATE_BOOL(op_done, PMSMBus), + VMSTATE_BOOL(in_i2c_block_read, PMSMBus), + VMSTATE_BOOL(start_transaction_on_status_read, PMSMBus), + VMSTATE_END_OF_LIST() + } +}; + void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk) { smb->op_done = true; diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index e6d8d28194..7b24be8256 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -43,12 +43,20 @@ typedef struct ICH9SMBState { PMSMBus smb; } ICH9SMBState; +static bool ich9_vmstate_need_smbus(void *opaque, int version_id) +{ + return pm_smbus_vmstate_needed(); +} + static const VMStateDescription vmstate_ich9_smbus = { .name = "ich9_smb", .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, struct ICH9SMBState), + VMSTATE_PCI_DEVICE(dev, ICH9SMBState), + VMSTATE_BOOL_TEST(irq_enabled, ICH9SMBState, ich9_vmstate_need_smbus), + VMSTATE_STRUCT_TEST(smb, ICH9SMBState, ich9_vmstate_need_smbus, 1, + pmsmb_vmstate, PMSMBus), VMSTATE_END_OF_LIST() } }; diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 7bcca97672..fb55c44444 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -43,4 +43,13 @@ typedef struct PMSMBus { void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk); +/* + * For backwards compatibility on migration, older versions don't have + * working migration for pm_smbus, this lets us ignore the migrations + * for older machine versions. + */ +bool pm_smbus_vmstate_needed(void); + +extern const VMStateDescription pmsmb_vmstate; + #endif /* PM_SMBUS_H */