From nobody Sat Jul 25 12:03:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1784496038; cv=none; d=zohomail.com; s=zohoarc; b=KPioiBvcN6YXjhfRsF2M3iDVwCrh7i6oOAesnT0HzDsgrZb9B5fbHWmtTUbyvT/h5pKC/ukGwRdZBVbSsex2fDnYDFPwk4Rm5Il1gxiCH4nuLYjrKY8s4RGQqQ8MnbXkzbUKMETTZcWPWVKdaygceke+CTQZefiwCbGkIzPFZGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784496038; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=c7xQW0Y2c2Ttvhuy3nxoGn0GEZdics6zlvTb6qkTGRA=; b=TMlasTgqgQjgjyKE5TM7YuOOJe1AnYpGlns9xXCpWER9wSUzAvdUoVM3nuspHh3DUUfNV3GJ7HudHtkgtrjM1DcPvWdQ9zvQni7r15bEh6OpKqVcXtSaO3rJaXkmYIDdRxez0dL48VnnubVVZA8eo2oB5SF1DMt6fjXqLKwDPq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784496038351441.6982602912525; Sun, 19 Jul 2026 14:20:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wlYvG-0007XH-OT; Sun, 19 Jul 2026 17:19:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wlYvF-0007Vn-3j for qemu-devel@nongnu.org; Sun, 19 Jul 2026 17:19:41 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wlYvD-0006pn-KX for qemu-devel@nongnu.org; Sun, 19 Jul 2026 17:19:40 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4954dff6536so12327815e9.0 for ; Sun, 19 Jul 2026 14:19:39 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-1c56-1500-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:1c56:1500:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4954a2a24b6sm234235155e9.3.2026.07.19.14.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495977; x=1785100777; 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:content-type; bh=c7xQW0Y2c2Ttvhuy3nxoGn0GEZdics6zlvTb6qkTGRA=; b=QeDpfyCNG65BGoQfL9W7iQ9CbrPytC0sCp7CKS0RLs/DXSluBtsfgNgvsAYaQmMgLr /4D923B4fP25qir18G95gP7kMZq9SZorclYAJdw6QiUVwgB5I7AE+vAlrsXbdxbOCuSN FjLCEBBYdRTXhQ4cwn5cMTmDFfpNC02HZriJDWYz5iWU0DW8xryDD1J2v6n0GJQX22mD fn6iMMHBhs/ppEqn2i7bDALlDRvHbMNA43dj1OL+7mksa0NfEXNfpzC7VkWN5Zyw2tUW kqPBYcg+NdfkUUCa4BXBy0A3XrS+EgUhhx+Xl1ABph2NUH29fuHrv0SIPRRL3T6iMtI9 P35g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495977; x=1785100777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=c7xQW0Y2c2Ttvhuy3nxoGn0GEZdics6zlvTb6qkTGRA=; b=Cnf+kh6rAqJi7SXBp03bYk5/QLcDxFUWizkAdAIVBRYH94PUaOPy5a74CWyOnxwyHJ muvbP5ok5lmq3CBlmDfSyHapw4kwZKEpcUcJUktNBIsjJUrB+NXmJo9GZ1dBJHT9QREV 1oa/E8Fk1BJGedmZODaEQzz1HWaO8RyFwGdzMmvtH3tJVgnhE9sBZ0P8AW9Lm6rI7hkY gkf0KipFjz1Arv+F/TrVNtZ83J3yyPPSNdHmahnvuYAbBtw6sIzA8VEPEdF/vyx4+HsZ wX65EbgJCsH8TbkFj7ADoulb4UCH9DOTtM0gcBu/VWvwkjD1/Kgh/Ccmt9tWn8WKWYrd cWFg== X-Gm-Message-State: AOJu0Yy7XoOgbzq72uyOiMPwyw2ck/n3rybpyANRiDYG6tp3uwblXwJQ dBXIutNOpm3Q6qN3QnXjvfnzhcdtoEHIT5peZHtJEcv50JmVIQUHQBxhzjJLkQ== X-Gm-Gg: AfdE7clxYYfU+Wz6cEnhazvX7aig6WN1VlxSxjKFeOvjqo5P0oqNNy0dD0ZuhVtjEmc gGaM77F/RnNerJYOedZYJRi34nUK1fgoAtqSNHBCKd5jBsLODLlkAXmszrU6juUs76RJZqlpxQT yxRlgNEVEJYoG2TSZFV4TUfoxk+AEvXswEWxx061thj5nhXaMMhpMVST8arMic1l6fa7rXG7D/k mcA6bsk5ZFD0bXH83wzmygGgic+mJtQfp5SFuBN4GjddQf/0+uL7Sl6RLGg+f4S2f7InP+HAZ2h hw9ttvoA3ju4gQkuPndbruhTIOmtLsN9fZUpqHj36COkq820tHWoDpKKn66Pd7OcWZWBQAGnBZ2 eyauLOGng7VXOe/+H/cNi90eWW5AmEZRx3yCYc1A7BTjpT0K2lNYxcWQTia9BqtVSnGFNVBm+eO eq+0V/yZZPQPFFurocXD1me/K3PX0U5mrRlbG2Y4NpD2WVYOD+3pHf5H4hs+FK4q0JLi+8+IIbX nrVa/X6YS1Aftt7bCebeCjbaYHD7sdlokYi X-Received: by 2002:a05:600c:3b91:b0:490:c6c2:52 with SMTP id 5b1f17b1804b1-4954a3d0065mr154286965e9.3.1784495976828; Sun, 19 Jul 2026 14:19:36 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Bin Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, Bernhard Beschow , Christian Speich Subject: [PATCH 1/2] hw/sd/sd: Fix error case for CMD18 Date: Sun, 19 Jul 2026 23:19:22 +0200 Message-ID: <20260719211923.1079282-2-shentey@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260719211923.1079282-1-shentey@gmail.com> References: <20260719211923.1079282-1-shentey@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=shentey@gmail.com; helo=mail-wm1-x32c.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, FREEMAIL_FROM=0.001, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784496039492158500 Content-Type: text/plain; charset="utf-8" In commit 468fa450a7e0 ("hw/sd: Switch read/write primitive to buf+len"), `sd_read_byte()` changed its contract to return the read size rather than the read value (and was renamed to `sd_read_data()` accordingly). In an error case, however, `sd_read_data()` returns 0 by means of `dummy_byte` which is the code for the old contract. Moreover, `sdbus_read_data()` asserts the virtual method `read_data()` (and thus `sd_read_data()`) to return a non-zero size, i.e. to make progress and not loop forever. Fix the code to behave like the "DAT read illegal for command" case. Fixes: 468fa450a7e0 ("hw/sd: Switch read/write primitive to buf+len") Reviewed-by: Bin Meng --- cc: Christian Speich --- hw/sd/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3360757004..a30c541df0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2860,7 +2860,8 @@ static size_t sd_read_data(SDState *sd, void *buf, si= ze_t length) if (sd->data_offset =3D=3D 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK", sd->data_start, io_len)) { - return dummy_byte; + *value =3D dummy_byte; + return length; } partition_access =3D sd->ext_csd[EXT_CSD_PART_CONFIG] & EXT_CSD_PART_CONFIG_ACC_MASK; --=20 2.55.0 From nobody Sat Jul 25 12:03:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1784496027; cv=none; d=zohomail.com; s=zohoarc; b=TlHVu4EDBgUNgJz+q0UuF2TYTJkdzIJrEgk/fR3JLG7ljjMWttpPFIuAy2P62f+P66XwQxm29fJ6LyTiC1JDvc5OfG0z52ciH/iLbedXAKhLGItNOG887oGepU0DAI1mVJgEciQuHZXhkhWf4PbeMrdj775jhPgQp1tnC1furoo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784496027; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xwWetVbSJViUHp5bb0Y3AMHj8TPDUE3K1eNxqHubiHc=; b=GYliWawBh4WIxZoD2Fn5duMKtOZu5vtXb37wkiKEyaCJMukGdoI9e7FIdy6qz0Gt9g1/iSouJoifK/YtA50Ar2Vk0fVGO2MjMEz2k5dPvQGoouwrK4GOGxYwemTIJDC50MR1gPM9duzTgqQxoO6GUkYhwYVMkEIo0GBOLdmw+jk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784496027338801.8086756942793; Sun, 19 Jul 2026 14:20:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wlYvH-0007XM-7U; Sun, 19 Jul 2026 17:19:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wlYvF-0007Wc-Ua for qemu-devel@nongnu.org; Sun, 19 Jul 2026 17:19:41 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wlYvD-0006ps-TW for qemu-devel@nongnu.org; Sun, 19 Jul 2026 17:19:41 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so65382975e9.1 for ; Sun, 19 Jul 2026 14:19:39 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-1c56-1500-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:1c56:1500:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4954a2a24b6sm234235155e9.3.2026.07.19.14.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495978; x=1785100778; 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:content-type; bh=xwWetVbSJViUHp5bb0Y3AMHj8TPDUE3K1eNxqHubiHc=; b=eakdPSVLZBP0qx9ODlnuuYn6T2hKuo50wUECPFGj1lmE0YO1jMn1fo1mEw6nlTC414 OJEhH07wEJUEUSaHm2M6Zg+yE40hEpkjuNj3dUSYXVxzL+J69u5zd/PUnr6GgS3y0ajW 0RCZIFKJkt5lGQ1h/GtE0lgS3B5PPo6I/nCD5sVVP6H5ZuoKN8iqnO6zfTzhlUVrNGqh Fo8bEKXugId8OMB9PYF/FlbPLyTag2UIuQxz5v9Y7/odB9FNpd7XTi4jDV1k5bqxiGWG wiHEI2C4czSpd+M4LhhifuJ3apbRQ17DcAvWxBc+nxs/prTiHyoNf9EsDP/icJJcdVEl EXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495978; x=1785100778; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xwWetVbSJViUHp5bb0Y3AMHj8TPDUE3K1eNxqHubiHc=; b=Y1n0Rc9ZmOY0OyjPTiV+zqNQfIsAemi6U/aNb+PHwlRL1qxGzYTwfPCPSKT9dsXL3s x/TCb91STuGl7gLgd8d3KY1uzKubO3IqcHs+a1X67vm8ZO/U6u43+JyyrRbNktncxCHw VLyp+YdfoBmKrla675weWs3rsi4lfpzjk6OrcQVaamzv+UOI3/6ER5Mhbrs4sW+4dLEf /gklgClUit80idpJi4/H9qckrOmDTGRegKGjqAS0P2yic3FYs2KWTZgZ4V1CzGIb8Kn+ AmGlGQcQixP4XR2wUenvxdClzqIDcXjbGfLNrPUJy44Vd7QHk6cuz2klAkwHmXi2bY12 lKWQ== X-Gm-Message-State: AOJu0YxglkhWXQ7159k8EaFbZ7r5mPb5uF8GUZ3HuoiRlt3e7QW0dzNR w5Wx4nVYzbReknEvYRTDT7Cphji/wkQPya8KptHC5mWpELmQgX9mtEOjznbP6g== X-Gm-Gg: AfdE7cmPoIwWyDS8KkUAdoxiJMEV33x7fpgpOkDRDMFA5q7deH8ks8gdds1UynaHP9k 7Mw2t/qHmlbKzxV4AiCvgR3OJDHuJTdOjL6swHmcQ+OXdLWRUuB6z62ojVB6MITHcvojqQ7m4h+ Zt6sM0ibbSp96qTj3OCCrt3WTdERDOYf5ns5b144TB0FEVEOJ57Z/o40gnsLKV1iWhuPj2cg87E Sb7uTA6FVX5e8ZF/i0b+zCvU1zHUEMgrNf+8ETIdVcP9ckrGasV+0yHC9NtT/esYi/xN6RpqVDs 1SBbq/J0bqm03AHy73adGO+He3R+Cmh/vD/8rolpdw+/Xw2ACpR8OgwqMem/rNn5atjfimhTsSQ E6RcVjYLOE3Mt/yzNMLf/Z1oG0UUMSwv5ihrvpsfJoZHI51G5lvAlww6kRIxx7Bi3x5qKseD9Qi TD+NoREydZbXXMaLY+qQeLzdWKQJvtbCncbJQ/DVn5woS9yiZFveyICTe9jouJXKvkKYt0oduo8 1WU3wGDBTgTgyrI1yIuocuBzEhxqLTLOQxN X-Received: by 2002:a05:600c:e54a:20b0:495:5d6d:9cd5 with SMTP id 5b1f17b1804b1-4955d6d9e31mr15181025e9.27.1784495977865; Sun, 19 Jul 2026 14:19:37 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Bin Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, Bernhard Beschow Subject: [PATCH 2/2] hw/sd/sdhci: Extract uSDHC-specific quirk Date: Sun, 19 Jul 2026 23:19:23 +0200 Message-ID: <20260719211923.1079282-3-shentey@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260719211923.1079282-1-shentey@gmail.com> References: <20260719211923.1079282-1-shentey@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=shentey@gmail.com; helo=mail-wm1-x335.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, FREEMAIL_FROM=0.001, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1784496029601158500 Content-Type: text/plain; charset="utf-8" In Linux, the ESDHC_MIX_CTRL qirk is guarded by esdhc_is_usdhc() while the eSDHC code path uses the standard SDHC interface. Extract the quirk into a new `usdhc_write()` function. Fixes file system corruption on emulated i.MX53 where Linux' esdhc_is_usdhc() returns false. The same likely happens on e500 and imx25-pdk machines. Fixes: 75e98bc4f859 ("hw/sd/sdhci: Add TYPE_FSL_ESDHC_BE") cc: qemu-stable Signed-off-by: Bernhard Beschow Reviewed-by: Bin Meng --- hw/sd/sdhci.c | 73 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index c86dfa281f..e58a610397 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1795,34 +1795,6 @@ esdhc_write(void *opaque, hwaddr offset, uint64_t va= l, unsigned size) sdhci_write(opaque, offset, value, size); break; =20 - case ESDHC_MIX_CTRL: - /* - * So, when SD/MMC stack in Linux tries to write to "Transfer - * Mode Register", ESDHC i.MX quirk code will translate it - * into a write to ESDHC_MIX_CTRL, so we do the opposite in - * order to get where we started - * - * Note that Auto CMD23 Enable bit is located in a wrong place - * on i.MX, but since it is not used by QEMU we do not care. - * - * We don't want to call sdhci_write(.., SDHC_TRNMOD, ...) - * here because it will result in a call to - * sdhci_send_command(s) which we don't want. - * - */ - s->trnmod =3D value & UINT16_MAX; - break; - case SDHC_TRNMOD: - /* - * Similar to above, but this time a write to "Command - * Register" will be translated into a 4-byte write to - * "Transfer Mode register" where lower 16-bit of value would - * be set to zero. So what we do is fill those bits with - * cached value from s->trnmod and let the SDHCI - * infrastructure handle the rest - */ - sdhci_write(opaque, offset, val | s->trnmod, size); - break; case SDHC_BLKSIZE: /* * ESDHCI does not implement "Host SDMA Buffer Boundary", and @@ -1891,9 +1863,52 @@ static void fsl_esdhc_le_init(Object *obj) qdev_prop_set_uint8(dev, "sd-spec-version", 2); } =20 +static void +usdhc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) +{ + SDHCIState *s =3D SYSBUS_SDHCI(opaque); + uint32_t value =3D (uint32_t)val; + + switch (offset) { + case ESDHC_MIX_CTRL: + /* + * So, when SD/MMC stack in Linux tries to write to "Transfer + * Mode Register", uSDHC i.MX quirk code will translate it + * into a write to ESDHC_MIX_CTRL, so we do the opposite in + * order to get where we started. + * + * Note that Auto CMD23 Enable bit is located in a wrong place + * on i.MX, but since it is not used by QEMU we do not care. + * + * We don't want to call sdhci_write(.., SDHC_TRNMOD, ...) + * here because it will result in a call to + * sdhci_send_command(s) which we don't want. + * + */ + s->trnmod =3D value & UINT16_MAX; + break; + + case SDHC_TRNMOD: + /* + * Similar to above, but this time a write to "Command + * Register" will be translated into a 4-byte write to + * "Transfer Mode register" where lower 16-bit of value would + * be set to zero. So what we do is fill those bits with + * cached value from s->trnmod and let the SDHCI + * infrastructure handle the rest + */ + sdhci_write(opaque, offset, val | s->trnmod, size); + break; + + default: + esdhc_write(opaque, offset, val, size); + break; + } +} + static const MemoryRegionOps usdhc_mmio_ops =3D { .read =3D esdhc_read, - .write =3D esdhc_write, + .write =3D usdhc_write, .valid =3D { .min_access_size =3D 1, .max_access_size =3D 4, --=20 2.55.0