From patchwork Mon Sep 18 10:17:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 724147 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1601159wro; Mon, 18 Sep 2023 03:18:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdT0hNHbyNCF7l9XqynJDaCLOXmf6+Q6T+vov9bDLXuRnJIUKRF9Rq4rOSbntCVETFUv/I X-Received: by 2002:a0c:b2ce:0:b0:64f:518d:ac8d with SMTP id d14-20020a0cb2ce000000b0064f518dac8dmr8544529qvf.25.1695032330949; Mon, 18 Sep 2023 03:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695032330; cv=none; d=google.com; s=arc-20160816; b=UXZnL/0058XoqkctZnzK9AtxZBgWdkaSRQHjlaN+c3Jjwu2P4sVtrkQL4Q1ZGwlvEa h1hDml5hTahl0S1dLMssIX5BYACC0qR3AgGik8sMu8/KRun7iU0Qaa5tAuLigiuDRQiU wq1E/gUFUruMW+/JU7pv1b0ggJrBCoKNIvNDcTX+7bdYFllKucb0yUNyHFVT+GRbKLIq LN0QK86/Ufx3gGFXgfxX/DcowpPpfbQYSfB5d21J/Z7IHTNyr4lX7ngLfFEyfeQt4xSO U+1FNQZ9od7Sk0BlpCDTfrdV3ihFaL+fGDAT8Zdl1Rtl0lov7JVdQIkXIdIOFOWV3LHg GRaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+N+N/3iRKVrfEHVPUQcucmLszQ7ytIQTEiwcco5Pois=; fh=9n/Cm2KnMX6Qk7SoVbKt4LcEa/gSBuZo6NwnCSpbrp4=; b=wlGKxhn3dcHDL6dOvrjpNoJ8PIFSDtpNsaMpJ9vEWQIUnWagz0cRlqPbTV4DL/G+53 gi6ZcxdFZnMEQXVZhDTBJie5jyxyJSrNOiuFvOYFYsdByAnW5WM6aBAJ3mKB3hPvvDwK qdvHWfoAauNMJbZH8MIQmoHnjj2oCD/+2Fg8AR0uRWCKwhqce2DUg8ESNIFv//WwZE21 iuPnGLnwj6Ym0y155xoyQ2j71jUDVry2JOHJ1i7v6BtmWr3EaCSN+A4EJw18ca1euFnq 6pn5/IqIz+OawSw7a7ev65T14bqg+j7gWvgdR3Sv5clTpToBo9PIFAXbfXB6CWyeqLAE Qm9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R6YxzazM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l2-20020a05620a28c200b0076da614eba1si6176308qkp.170.2023.09.18.03.18.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Sep 2023 03:18:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R6YxzazM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiBKE-0006I6-CE; Mon, 18 Sep 2023 06:17:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiBKC-0006Hi-7N for qemu-devel@nongnu.org; Mon, 18 Sep 2023 06:17:52 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiBKA-0006nu-C8 for qemu-devel@nongnu.org; Mon, 18 Sep 2023 06:17:51 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-31f7400cb74so3808291f8f.2 for ; Mon, 18 Sep 2023 03:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695032268; x=1695637068; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+N+N/3iRKVrfEHVPUQcucmLszQ7ytIQTEiwcco5Pois=; b=R6YxzazMzK0pyfjwwiHM9RVk2MMjey8oBDhjW/fpjUzLkhZYYJCr25tewfft2L+yeA yuL+sLmxgnyX1pI3O4/ZulhFh48pvZIGO8DQ8PIFs1O+NkS/C86tSG6bJM1zH7ayoyLu +vpOEJDjlTpCzyJb4FUHGb07zzVdVRI4jw3KoAtPCYIF2atsoaT/Vcpyiym5uTlokO85 hsI4ZU+TcySkH4bk1MJ4cQ0yFmCLvIiFPG7kxrhtYSQzuduTMOC1gp7/245hr3okYHdn VIMlSWfzUbwXxit9QC2lClyRF7XnWMp34RM5Qv6V5afA3WpatRjuIHtGESp59X5VSd1Z EJWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695032268; x=1695637068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+N+N/3iRKVrfEHVPUQcucmLszQ7ytIQTEiwcco5Pois=; b=FZsCgjWl2/jZHmZXDx3/ilJ/ca2D7reOL/koOPafzUbAUHG4tNiU6p8ILtPSGmvGZU 0fdNPacG8NYJzlRK13BZrAHGLKZ7eGDBul3mwpyCUlAhyuq0x2UJotJh3FG4xuGpElcK VS7oMeO+nJ7fAEnCdqIj/KIapOcT2dduGYJDtDR6oiXpqerts4br1ceeGFlhN+pRHZzE YIQM0YXGTyFJcuTUXykZo7lHokBLH0i/pzD9uCkb9bC5xs6wggAPdQ8od7yqkTDTxhCE 4258eawA/wAp4aA8Ro9HYVZbRcr/GVWqTYIf3tpXMoaWi7rprPaeJLSUVSP5AqhIjVeM GHTQ== X-Gm-Message-State: AOJu0YyNRGoE2FpyrbpzBy1S2OIC3ADzDjRPgos6X9EKKUojLeDgCCd9 PazGTXklmHgJEjRqnHgfAW9VHnFACuEpVdf9I8Yxlyz9 X-Received: by 2002:a05:6000:703:b0:320:121:2300 with SMTP id bs3-20020a056000070300b0032001212300mr5316225wrb.1.1695032268227; Mon, 18 Sep 2023 03:17:48 -0700 (PDT) Received: from localhost.localdomain (5.red-88-29-175.dynamicip.rima-tde.net. [88.29.175.5]) by smtp.gmail.com with ESMTPSA id z2-20020adfd0c2000000b0030ada01ca78sm1139386wrh.10.2023.09.18.03.17.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 03:17:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , "Daniel P . Berrange" , Eduardo Habkost , Alistair Francis , Paolo Bonzini , Anton Johansson , "Edgar E . Iglesias" , Markus Armbruster , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Mark Cave-Ayland , Bernhard Beschow , Peter Maydell , Alessandro Di Federico , qemu-arm@nongnu.org, Luc Michel , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/2] hw/sd/omap_mmc: Do not reset SDCard until being fully realized Date: Mon, 18 Sep 2023 12:17:35 +0200 Message-ID: <20230918101736.23905-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918101736.23905-1-philmd@linaro.org> References: <20230918101736.23905-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We shouldn't call QDev DeviceReset() before DeviceRealize(). Since the OMAP MMC model is not QDev'ified, it has to manually call the SDCard reset() handler. This breaks QDev assumptions that DeviceReset() is never called before a device is fully realized. In order to avoid that, pass a 'realized' argument to omap_mmc_reset(). All cases are explicit manual resets, except in omap_mmc_write() where we expect the sdcard to be realized. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/arm/omap.h | 2 +- hw/arm/omap1.c | 2 +- hw/arm/omap2.c | 2 +- hw/sd/omap_mmc.c | 21 ++++++++++++--------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index 067e9419f7..d331467946 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -808,7 +808,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base, struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, BlockBackend *blk, qemu_irq irq, qemu_irq dma[], omap_clk fclk, omap_clk iclk); -void omap_mmc_reset(struct omap_mmc_s *s); +void omap_mmc_reset(struct omap_mmc_s *s, bool realized); void omap_mmc_handlers(struct omap_mmc_s *s, qemu_irq ro, qemu_irq cover); void omap_mmc_enable(struct omap_mmc_s *s, int enable); diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index d5438156ee..3afeba6f86 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -3728,7 +3728,7 @@ static void omap1_mpu_reset(void *opaque) omap_uart_reset(mpu->uart[0]); omap_uart_reset(mpu->uart[1]); omap_uart_reset(mpu->uart[2]); - omap_mmc_reset(mpu->mmc); + omap_mmc_reset(mpu->mmc, false); omap_mpuio_reset(mpu->mpuio); omap_uwire_reset(mpu->microwire); omap_pwl_reset(mpu->pwl); diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index d5a2ae7af6..ef9b0dd60a 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -2253,7 +2253,7 @@ static void omap2_mpu_reset(void *opaque) omap_uart_reset(mpu->uart[0]); omap_uart_reset(mpu->uart[1]); omap_uart_reset(mpu->uart[2]); - omap_mmc_reset(mpu->mmc); + omap_mmc_reset(mpu->mmc, false); omap_mcspi_reset(mpu->mcspi[0]); omap_mcspi_reset(mpu->mcspi[1]); cpu_reset(CPU(mpu->cpu)); diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index edd3cf2a1e..3c906993eb 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -287,7 +287,7 @@ static void omap_mmc_pseudo_reset(struct omap_mmc_s *host) host->fifo_len = 0; } -void omap_mmc_reset(struct omap_mmc_s *host) +void omap_mmc_reset(struct omap_mmc_s *host, bool realized) { host->last_cmd = 0; memset(host->rsp, 0, sizeof(host->rsp)); @@ -314,11 +314,14 @@ void omap_mmc_reset(struct omap_mmc_s *host) omap_mmc_pseudo_reset(host); - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. When omap_mmc is - * QOMified this must move into the QOM reset function. - */ - device_cold_reset(DEVICE(host->card)); + if (realized) { + /* + * Since we're still using the legacy SD API the card is not plugged + * into any bus, and we must reset it manually. When omap_mmc is + * QOMified this must move into the QOM reset function. + */ + device_cold_reset(DEVICE(host->card)); + } } static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) @@ -556,7 +559,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset, break; case 0x64: /* MMC_SYSC */ if (value & (1 << 2)) /* SRTS */ - omap_mmc_reset(s); + omap_mmc_reset(s, true); break; case 0x68: /* MMC_SYSS */ OMAP_RO_REG(offset); @@ -613,7 +616,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base, exit(1); } - omap_mmc_reset(s); + omap_mmc_reset(s, false); return s; } @@ -643,7 +646,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, s->cdet = qemu_allocate_irq(omap_mmc_cover_cb, s, 0); sd_set_cb(s->card, NULL, s->cdet); - omap_mmc_reset(s); + omap_mmc_reset(s, false); return s; } From patchwork Mon Sep 18 10:17:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 724146 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1601096wro; Mon, 18 Sep 2023 03:18:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1nXfNKXz1B6WlNcEtCiQDkUirQHDxv0vogF30O5plvxzdIzuyX1hdl0aR+HR32kTp+tZ9 X-Received: by 2002:a05:620a:226:b0:76f:1d46:8511 with SMTP id u6-20020a05620a022600b0076f1d468511mr8221956qkm.44.1695032319030; Mon, 18 Sep 2023 03:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695032319; cv=none; d=google.com; s=arc-20160816; b=izythBnGuysBbFgLQ1fnvwD2CVbCHbEGOdzCmPU/CWoHEKaFvy3mU2V4z4pWbnysLo QD6vrTmj2NmvryCQCLS9Ye9N76FlJoruHEXheo3b3fvbdAWxML2tjDe20dQLHtrHZHSE rPyegLVWgPMFMo4k1/Ng9iUjMhI0TmdEu6jZJbYbhH2miYPd6xtJNnSWDiSuh5oUIKuC AV5IhAf/hS7f6zsrKmrD9hWjXPdm7yp4dRdxGYWlA81db1eAaTkwniUOf6JbRSTD2hM4 MdmvsKa4QSX1vssMCEJa4gmmhY68HQGCFF7TEAP6b2pq55U7rL4Wrq1aGF1nVHGvfVUS ISqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8I52HFJ7JIIVf6/kc1x9A3KkqjzDotpu4ox1BgoUxm4=; fh=9n/Cm2KnMX6Qk7SoVbKt4LcEa/gSBuZo6NwnCSpbrp4=; b=k+NvX50CDSPDYIAN2hdtSAyn0WJxZhkRwNyjKERYBeZbvFcQPBk1JpTWN9dZ4aFJBw sPiJgepJNSjQmkHybF7NNDy7e2kT94DeBPXbX+Ol4FmuvclEHEh/UJGUDOwMwq9Dv2ch vaKLdLSWxMy2jqC9mjoI6+NT5BaA0nmOhZC6ldmL9j6ZpcVRoGyiwhm1gFiG7tzZHjAv 9k8xCj0BLRcOGfBuRSDsv7ejBTIcUM3bHiW+F6YfA+V99s022Gf6/n5RC7Ad504xX6pJ Kq7vJ420YIcfjOq14HxUp6PGMLDCm8fzKEq7oE6VL4/x82lfKtTGd8YcMO9fFsITnbWO o9OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NO/fDZs9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o29-20020a05620a0d5d00b0076da9a5c93dsi5687375qkl.335.2023.09.18.03.18.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Sep 2023 03:18:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NO/fDZs9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiBKM-0006JW-TD; Mon, 18 Sep 2023 06:18:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiBKJ-0006Iq-Tw for qemu-devel@nongnu.org; Mon, 18 Sep 2023 06:17:59 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiBKH-0006ou-DW for qemu-devel@nongnu.org; Mon, 18 Sep 2023 06:17:58 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4050bd2e33aso7090895e9.2 for ; Mon, 18 Sep 2023 03:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695032276; x=1695637076; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8I52HFJ7JIIVf6/kc1x9A3KkqjzDotpu4ox1BgoUxm4=; b=NO/fDZs9W5HiqDat34WSBqcyUio2okr25QwI6p7cCubnPGxOYMSjJUAt6dy3hh81YH 21btOA8H3QDOeJMQiOQJrcfVVBbwsabxmWdKnrYBmVjrYbBypTVyT91Reaot9vk5GXE9 vw2aExYzkuIQf34C+wzcRQeeCm3O+IheKsWK7OKRUFJb9RDyLxW0EWp8HkQ5ONLtT920 gC8Fgli4TFKpfFdiBzr4JHiYJRegpW5c1CA1LzzRBziKvFoaaTiM7O3WBrCmkuT1njUY +jS1BSbqAHIlCMCxQqWpMtCQXsQZgULpDODi8XLKpDRdDBszwsGIYGjPcW8bGSQX7hz3 FDPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695032276; x=1695637076; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8I52HFJ7JIIVf6/kc1x9A3KkqjzDotpu4ox1BgoUxm4=; b=qP05ST8y5ktED1AoDxBVrZDAdk+2svM4fA1+Yn718h2qTq7dxrh7hcQAEDhNKAP4uk XJ6WMIpvpI+jbuAAjSfO0fJcfg2rjbbYGOxigqadZQDXk0x3xm4q7raFF9JrVQrxgunm yLenaYpKfR3t0U/Ia96vkaD6ebPYbWAruzGV0JwZIHSf+HvTBKxgcxE9WS/8pqcJ0pGu STh5ZlaHkgWrinPin/E4w1n5qg4RA0OgX9M2WwkI/fDXx0ypJJlwzeOY7dgCGs8dbq4H fa9TyYIqd+NiO+P2wzuXPG4p+2fNWLFW+AMbCg23aKzXGjWXpA5qZOHWyg9NjCGBCA4e 5wWA== X-Gm-Message-State: AOJu0YykxyHCHpATNckaMOQR6oQAQsngWo5yHWN/oJie/Wg0khw6E0YJ 8taBcqj8bnn5esdOzYeFc2a9T3nCE2WlyNouNCPRpNZh X-Received: by 2002:a05:600c:2901:b0:401:906b:7e9d with SMTP id i1-20020a05600c290100b00401906b7e9dmr7999543wmd.18.1695032275800; Mon, 18 Sep 2023 03:17:55 -0700 (PDT) Received: from localhost.localdomain (5.red-88-29-175.dynamicip.rima-tde.net. [88.29.175.5]) by smtp.gmail.com with ESMTPSA id c4-20020a05600c0ac400b004030c778396sm14945294wmr.4.2023.09.18.03.17.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 03:17:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , "Daniel P . Berrange" , Eduardo Habkost , Alistair Francis , Paolo Bonzini , Anton Johansson , "Edgar E . Iglesias" , Markus Armbruster , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Mark Cave-Ayland , Bernhard Beschow , Peter Maydell , Alessandro Di Federico , qemu-arm@nongnu.org, Luc Michel , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 2/2] qdev: Ensure devices are fully realized when calling DeviceReset handler Date: Mon, 18 Sep 2023 12:17:36 +0200 Message-ID: <20230918101736.23905-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918101736.23905-1-philmd@linaro.org> References: <20230918101736.23905-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We shouldn't call a DeviceReset() handler on unrealized device. In order to enforce that, add an assertion. CPU devices are a bit particular because we manually reset them in various places, so corner case them out for now. Signed-off-by: Philippe Mathieu-Daudé --- hw/core/qdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 43d863b0c5..c51b4c98de 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -252,6 +252,8 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, void device_cold_reset(DeviceState *dev) { + /* TODO: Also cover CPUs once we removed manual calls to cpu_reset() */ + assert(object_dynamic_cast(OBJECT(dev), TYPE_CPU) || dev->realized); resettable_reset(OBJECT(dev), RESET_TYPE_COLD); } @@ -280,6 +282,7 @@ static void device_reset_child_foreach(Object *obj, ResettableChildCallback cb, bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) { assert(!dev->realized && !dev->parent_bus); + assert(!device_is_in_reset(dev)); if (bus) { if (!qdev_set_parent_bus(dev, bus, errp)) {