From patchwork Tue Jan 9 14:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 123966 Delivered-To: patches@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4056022qgn; Tue, 9 Jan 2018 06:01:57 -0800 (PST) X-Google-Smtp-Source: ACJfBotlYrB8rXIoPYhpoRaPKpxyA4OFWjGS1OTzZPiuKSQGKaxSGVrr04ifFLsIslIEq4dYrWHg X-Received: by 10.28.238.6 with SMTP id m6mr12947365wmh.97.1515506517125; Tue, 09 Jan 2018 06:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515506517; cv=none; d=google.com; s=arc-20160816; b=qmDy+m60NloiUtU16yaqIIPwJ5DziFpLmuHnELdWPrayJ5fhOe8ITLveDbg9stKnSa SFmQxkn7jNa+wfTLuPQ0lSGIC1idG4zIttGlwrZuL6bWA8jS3SCQ0KHU65INOHXRVFbB 3L4a/3YuLngF87qYZ7NiASOiYNTQQWMaDVmoVXcYqhaGYGDOW8GdPd0H9pTcc1LnlLg9 nrhCNnoQCvUUko7BJiOWmFtcFdzjuImtfkIPFkBlpS7qjyftL6PzQej+NxWskQHQk1N0 N/kZYHlJkGu3FwEFUD3LNC84asmF+Sh6slEfoz7uz03ZQ+4iByOMHE8zf/8H7JDpaM6L kLrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yzVSrDm5d995q4LMUQVlMIeJos7qXSJWNS9RNe95x94=; b=Kgal7rYsavJ/F+5K28lkQM00m9DmmtdWRguGM0w2fBffF6yDohINsXIiFkZXi5nC1u V4MHc4Ao7a0gKBBgIGvM6FpAot+u9xh3ijauXfbw/aF6LJzBg2UGQJqNsLc8o+tXd6F6 hWwaKl3B2g/6Q3RVv7SwvzPr9Z5oEw16IN2G/I74uX8MBxarg5Wtz0ccI/c//ETwlvUJ WcjWuRnsQHaEVUnAw+G4jphGP9JHdEVnStQ4+S9s/VqiBEiLjvTGiX1W3UxCET+ByOhL 3AgIXwIIcneLrg+2X/RmoW2X0ukViWRoNoQMEAaLXZzq8i6/NrzwL9QPPWsx0g4PSsjb va2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id y44si2481830wrd.521.2018.01.09.06.01.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Jan 2018 06:01:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eYuTU-0003ek-JW; Tue, 09 Jan 2018 14:01:56 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 3/4] hw/sd/ssi-sd: Reset SD card on controller reset Date: Tue, 9 Jan 2018 14:01:52 +0000 Message-Id: <1515506513-31961-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515506513-31961-1-git-send-email-peter.maydell@linaro.org> References: <1515506513-31961-1-git-send-email-peter.maydell@linaro.org> Since ssi-sd is still using the legacy SD card API, the SD card created by sd_init() is not plugged into any bus. This means that the controller has to reset it manually. Failing to do this mostly didn't affect the guest since the guest typically does a programmed SD card reset as part of its SD controller driver initialization, but meant that migration failed because it's only in sd_reset() that we set up the wpgrps_size field. In the case of sd-ssi, we have to implement an entire reset function since there wasn't one previously, and that requires a QOM cast macro that got omitted when this device was QOMified. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell --- hw/sd/ssi-sd.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c index 24001dc..30d2a87 100644 --- a/hw/sd/ssi-sd.c +++ b/hw/sd/ssi-sd.c @@ -50,6 +50,9 @@ typedef struct { SDState *sd; } ssi_sd_state; +#define TYPE_SSI_SD "ssi-sd" +#define SSI_SD(obj) OBJECT_CHECK(ssi_sd_state, (obj), TYPE_SSI_SD) + /* State word bits. */ #define SSI_SDR_LOCKED 0x0001 #define SSI_SDR_WP_ERASE 0x0002 @@ -251,6 +254,24 @@ static void ssi_sd_realize(SSISlave *d, Error **errp) } } +static void ssi_sd_reset(DeviceState *dev) +{ + ssi_sd_state *s = SSI_SD(dev); + + s->mode = SSI_SD_CMD; + s->cmd = 0; + memset(s->cmdarg, 0, sizeof(s->cmdarg)); + memset(s->response, 0, sizeof(s->response)); + s->arglen = 0; + s->response_pos = 0; + s->stopping = 0; + + /* Since we're still using the legacy SD API the card is not plugged + * into any bus, and we must reset it manually. + */ + device_reset(DEVICE(s->sd)); +} + static void ssi_sd_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -260,10 +281,11 @@ static void ssi_sd_class_init(ObjectClass *klass, void *data) k->transfer = ssi_sd_transfer; k->cs_polarity = SSI_CS_LOW; dc->vmsd = &vmstate_ssi_sd; + dc->reset = ssi_sd_reset; } static const TypeInfo ssi_sd_info = { - .name = "ssi-sd", + .name = TYPE_SSI_SD, .parent = TYPE_SSI_SLAVE, .instance_size = sizeof(ssi_sd_state), .class_init = ssi_sd_class_init,