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: 1003467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="s/kH4jRw"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 433dq22m0hz9ryk for ; Tue, 27 Nov 2018 07:31:10 +1100 (AEDT) Received: from localhost ([::1]:38711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNXA-0007ym-2D for incoming@patchwork.ozlabs.org; Mon, 26 Nov 2018 15:31:08 -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-Google-Smtp-Source: AFSGD/UwbGabe9c2DTTPAOuWF1Q1MgYjya25wnXgJwPcqX6xWhgnlXJimvkdJuyaJLHvmbx7YhE3Vw== 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+incoming=patchwork.ozlabs.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 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 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 */