From patchwork Mon Nov 26 20:04:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 152075 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp337193ljp; Mon, 26 Nov 2018 12:32:42 -0800 (PST) X-Google-Smtp-Source: AJdET5fWmmPidNxi6OrEVu6UU7r4y+JhWFg7UMTYxWjRYGQkPUD/AiaVCps1VUM8dVF5En5KCQV7 X-Received: by 2002:a81:34c3:: with SMTP id b186mr31333329ywa.509.1543264362653; Mon, 26 Nov 2018 12:32:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543264362; cv=none; d=google.com; s=arc-20160816; b=Y/TYQhFVP2cxTYh7cTf4s86aVBxvRroAsHrCJ35QRZbLwKmJlQQxTSj1Sb0B8cek8L yf6NOnBB0Kc1Mhy0sKR2HSh7oHPsSHQH03zXzu9LfLf1+lekowzHr19oc+X7Nluuqjom 4dCEwrBTgnIGtuituDPfFM1Vm7//S3MBm3Dfr9GkLj7cpuLqFC+bZUum9EwHxJcKALK4 Zz5Y3UlFSF9viLbo5sA6OgF8tAm8nFsHNghQipyM3wKpGCxT2dNV+LW/0VDL1Oba8+bU 47TcjImHgfPHYx0esUjrDruqTCKBoEwAKUb+PCGyf8fLKElmDO1fzNj8SwlxVA6bPf/+ mYyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=pP0NdikIQIBMzSCyGr5RV91Em+ipclDyl4tVBpcjEcU=; b=K9govMRbZBLwCC3hJAbgWD2z+A8jinFP8oZ2cmwdKng6y+EzvMAew7cBc18T61A/Nu 8LUg6t8seDjw8gs9eFoP4J8a0usNGR4b3+B4Y6YkOe9WCYcO01HuclHc8dAEorzk+yBB IWrltTssnAxem8YT7z3sM+wCcZCXglN1iMmIZqJKGtQMdx9hmuU0GL6ekjCFvMCFAMKC QxxYvmNbMJE7GkJlrFM8P+HPYKdTHm0Saer7dE2LKqFvycrAVwUorWd9U5qZbCJfnGq0 bVCwAd/qwwuyxmeqJMem+QI6zkXdHbQMtpntdePPQHZKzfe1JD7ZgAc50GH8SqSG3sU7 rDBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="s/kH4jRw"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o1-v6si1052858ybo.280.2018.11.26.12.32.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Nov 2018 12:32:42 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="s/kH4jRw"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:38716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNYg-000196-3F for patch@linaro.org; Mon, 26 Nov 2018 15:32:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRN81-0001lO-E6 for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRN7y-0001Lu-Vw for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:09 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:34630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRN7y-0001Hr-K3 for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:06 -0500 Received: by mail-ot1-x343.google.com with SMTP id t5so17917349otk.1 for ; Mon, 26 Nov 2018 12:04:59 -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=pP0NdikIQIBMzSCyGr5RV91Em+ipclDyl4tVBpcjEcU=; b=s/kH4jRwW3d5tLkdGH9LPVbH4q+GAGAZwZ0Co13Fd8eZiBNFCTZE0jfH1azEu6qE64 7fBF2MOeOcPeqsH0f52/49UN3ReFT8hePjiEd4HeEXDv3dAYvEmNPN+MjoF+a9ABOQbV U1lW7GEJC5d503tjtJ6DGIICq346k0EO9XXeszxuIbHsbF9tUFTKUXrODFWgRgTaMi4n zngNUvjzEGK5gZ0Ei1ykANaMSpLSdmJnifmM6pEGA1oy4ejWUwIjRFwqasCmeKJFXN1e N2YYenn0Qf3s1Tn0m02sPtC6GQIW9gdVTAHH9vKA14LBngs0I3o4nUF7ALngFGRW0pHJ VYyQ== 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=pP0NdikIQIBMzSCyGr5RV91Em+ipclDyl4tVBpcjEcU=; b=CXaUr/AeoeD0PsO21iIVEkLTlqOf2CWZ9jpdIHwVUOyve3DdgRco1t4Mtz6MZeTN91 bGXQz8w6m8ZgLBW1jO+ci6EEc+WN8QY5dUoc1J0q+DAaRtH8/m8tn71HxQopPxZf/04q C4vBf7QZiztD3WsRp4CvFrFwgSm4KbLyIShNaEfRrTDkfj3letMm+b2X8t6pYYHNrWmr pR7lXOMsusX9iE6JZPmX2L9ADbQIU8ZXLAoqQLmvEuxYsj20MdLkFCbxqbD7jtbFOSY3 2NCXnn3re+Kkz1uCpxMR6CRs4cUG+T4IEUTWobKDLerTf1TEDMtTqnw6Z0OKYIYihx8n Ax5Q== X-Gm-Message-State: AA+aEWZqaudVFbShXveWPHVkYmMQKWo0O+CyBX+AxPWls64wM6SYLfiI VLdz2Jy1O6qc+LdSrSipfQ== X-Received: by 2002:a9d:4704:: with SMTP id a4mr17290834otf.325.1543262698715; Mon, 26 Nov 2018 12:04:58 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q203sm375082oif.33.2018.11.26.12.04.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 12:04:52 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 301CC1E1C; Mon, 26 Nov 2018 14:04:49 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 9C7FE30146B; Mon, 26 Nov 2018 14:04:46 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Date: Mon, 26 Nov 2018 14:04:29 -0600 Message-Id: <20181126200435.23408-11-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181126200435.23408-1-minyard@acm.org> References: <20181126200435.23408-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 v3 10/16] 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: Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- 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(-) -- 2.17.1 Reviewed-by: Dr. David Alan Gilbert diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 2f4dd03b83..91fe4821d3 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 8793113c25..2a9bc6e8c0 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" @@ -450,6 +451,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 */