From nobody Sat Jul 25 10:28:18 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=1784578341; cv=none; d=zohomail.com; s=zohoarc; b=Se3ZxDnJZABk7Q8OsaKXXjPSHAp1+BpTgYB5v7p1fQ9VvD0jNF4ga2s7RwtPKgCSYGYDqKGDLRN8ZMbSHNiu0/zmYUTzHpPtQ/QKIv/4GqzWOhQpN9dkiTzCAJRjNAoDbcPrzlHuQWchwrfUInYie0dp5oxweuS0DZ8Px3kzvU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784578341; 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=U/09Eb0HUBr/JHocdx6RIzxAMDkihyLBxhmQ0AfJ/9A=; b=Rp/4qio3lfAlCYGSapFoNzlGj/oxIg2GhS/Qxk4sGeGGpcDyMp3hQCmoZFtsXC+ovTeErJFz5PGmGz/MJzz4glvdzmpcM8G4X2mWvzF1R1nai2W86TctqR4N6RK7GvBGc117sXUECxHa12qCIupqSVeMSpTAwFbYca0m1ko5aFs= 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 1784578341571967.5493162768512; Mon, 20 Jul 2026 13:12:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wluL9-00065X-UU; Mon, 20 Jul 2026 16:11:51 -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 1wluL7-00063c-Dn for qemu-devel@nongnu.org; Mon, 20 Jul 2026 16:11:49 -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 1wluL5-00065l-VI for qemu-devel@nongnu.org; Mon, 20 Jul 2026 16:11:49 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-493f75f7172so82875935e9.1 for ; Mon, 20 Jul 2026 13:11:47 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-225b-5200-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:225b:5200:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-495653bfabesm15934935e9.10.2026.07.20.13.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 13:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784578306; x=1785183106; 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=U/09Eb0HUBr/JHocdx6RIzxAMDkihyLBxhmQ0AfJ/9A=; b=mblU+kogo00SPTfPJovoCn0wuFi6uzxh432w8uRnoZFuWjAZqYwzdE2CTG3FIylzbH QDiLDYgsd0nfBaCuAqE9EFllXMrlV6Z/XYDuKWrc3tQPz2KLwxUFb5UelPg62GEwsglV ZnZyIPuS+4frMeaFqaTdCZ0oya5SZs8+U39hFNte66eLr0uGyiGSRPNTC9k2ePwKER+h HYzEvk1Nv8XbA/EZt8uEOGtbIbj3j97mQhqha2bS9IS8k2gtdP8AFwJpHUL4EEaTZIOO I2NoBtvqi7HxMKM6i147oyXsxqzmUrK0M1DwqR5N4/d5WXtIGvRXKXVELIG499ksSSrv ki6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784578306; x=1785183106; 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=U/09Eb0HUBr/JHocdx6RIzxAMDkihyLBxhmQ0AfJ/9A=; b=RgZ9ltbFj/W4MP+92I2W5RmsWUZpxdlochNlQRBceTYOH/7Hj0K1VcaKrHGfJBiFYr 7c8x3mepTM6PMtcU+eeZrKvr9sZJhLjstoLJAxxQaPV+MfY9qA6UDfqKZWB+zAHx4zMa 0B4jBLzYinTnMHimnTNgpDHRtX/POKdgWXvMkpVWLYmmo5kz7dkpBA0c3nDn41anhv3k 6L4aJD0sgakBy43sd/rmQduNO9HlJ2XJ4hLJUrHoz0GAHrRqE7lSP4Q2OyZPvVmrfLB8 4QCxhLQRCCohH9xC6BJLWKSxRGFW5/rmAywgIq6QpQcHeume62yuju9qJv6U6tttYbhH 2pnQ== X-Gm-Message-State: AOJu0Yyb5Be0HaO/yqMi6m+ieo+XInwApfTcOSQFRpNmJCxqVwaLp3sF vSJNa6szxf2vEJQtxw5pvtha3xbY/uanfmUkPsin/PadOWQFluvAwvETMILWWA== X-Gm-Gg: AfdE7cn95duHdsqJzo79WA/uat7m88HyNgEyzu28GtOhi28KgcG0vyIxOxBM3TpG8Wg OONTmUiVYS3LSza05hUyodVB789lufiUX8CnAvKH/KJqt9MXhBqPhxOJIz6+j/GVWuQAxRelzEh KNXuN6au2IrFJhR3WkG+FN/G68pyq7jSTvhj63OyLhDR+ayI2XKT7TwE/3m/vMzkJU+L4doQH4/ pjVM+75UrI0deKmhFVuvOAwuh4pNu0/Ct5lSDqrHoyO7IC639neerOaumgJkVj6A00Dsep1SFTF x1+FaaqLs2eoMyWJQTRePYlhR2eaf98owRX+aOWRGhY+cqCRnJ57rtRbRsYcqm0qnwRg8XX50Lm DKnvFsakSpltq6/KqwD3J+15dufY/lIMv8VpryQtucfSVfQuuGjui//qYjltN5yyDMgB/BsErTX Vd00w/JFtvKTCaE2fKM9AZWezJsN+bVsPsOcJcnbDdtfQakfh8Z6ois3ytpHAZMQTXiEilPjpGU 3YXcoQ+W+nzqfAdb7k5dCfpkw== X-Received: by 2002:a05:600c:4593:b0:495:3a52:cd7e with SMTP id 5b1f17b1804b1-4954a40e2f3mr182158835e9.25.1784578306152; Mon, 20 Jul 2026 13:11:46 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , Bernhard Beschow , Bin Meng , Christian Speich Subject: [PATCH v2 1/2] hw/sd/sd: Fix error case for CMD18 Date: Mon, 20 Jul 2026 22:11:32 +0200 Message-ID: <20260720201133.24796-2-shentey@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260720201133.24796-1-shentey@gmail.com> References: <20260720201133.24796-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=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: 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: 1784578343251158500 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 Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 10:28:18 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=1784578328; cv=none; d=zohomail.com; s=zohoarc; b=dAE1I548kUSrJ8QKApy5Kb+Yqa1diPZ4oAlt8+3AyrFteRq391vz9Cx9LhqfU3qjeF2eytc4ZIxG8R2vCdsBXIubm0MjopYxL4wC+EGLGedDRjMjHzX+SZguYijAFG6BU7maLxcBhqpgPST3otsBKy3NunlEsDqn3UQ+ruodtIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784578328; 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=oOhv/ptlHCElcrsanQtecf376OnNniCHz8PAgnXjrx8=; b=eJL9uLJm5PPXIImw9xpnwCe/DEmJ+lAyG2iwcRtbwtq7lWwDxX+8HylmYftHWqsrrUfJ9KZgPbK9fhDQ5iWVwpJqY64gmNW6dMLZCX4ofKlYZ1siRn2wbJ+rXFZwNc7QICwsxJGWI3f1JRN6S+fq7wMPJie3A/YU2piBV8NrEA8= 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 178457832860767.55024465976464; Mon, 20 Jul 2026 13:12:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wluLB-00067N-F0; Mon, 20 Jul 2026 16:11:53 -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 1wluL9-00064e-2A for qemu-devel@nongnu.org; Mon, 20 Jul 2026 16:11:51 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wluL6-00065w-LJ for qemu-devel@nongnu.org; Mon, 20 Jul 2026 16:11:50 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-49553515a8bso25243315e9.1 for ; Mon, 20 Jul 2026 13:11:48 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-225b-5200-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:225b:5200:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-495653bfabesm15934935e9.10.2026.07.20.13.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 13:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784578307; x=1785183107; 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=oOhv/ptlHCElcrsanQtecf376OnNniCHz8PAgnXjrx8=; b=Q9bw4US0eXceDQbkwBlVjJ2K3efQmxOLdgHHvUZh8jR+n4sTnhZMljrq844QJ5kHAY xcQ0wUQfM3tqgZmzg5vLVfcGPfD4SVP0c2sN4yvpEbYRj6gyIN+6DBsGQZ7dPh/ZM0l0 r68Rw29vbZXuRUOQ29y+WZJ1KRqJSFvKEaGK83+RONPnScZRJ9k5XJk4WjUj1Fi6XHlx qBEJVfEN9GxAqexy/0D3wJd2Xr7LvSjjjlGO4OfCigx1om7d6UUqW64lyQkocLWorJyy 7WFbh2ThQW+ZFzyVNUPuYTQNAp2XfOLkEqyB+HUgoFuOZVdaFGfSW1BTOhvAQN0fMKkf n4qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784578307; x=1785183107; 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=oOhv/ptlHCElcrsanQtecf376OnNniCHz8PAgnXjrx8=; b=Pnc8vQKLFgiKwbjco2zc4WEg2prfiAUwWuZzlaKXzRaiBOhaVzfmnesyX2ouE+zVv9 Se+nnWcQNMT1I0ZMEPyJmsXepfn0t3d3WnEPu/sdjIybriGZzz5D8ZshnCfljvouJX6Z TgqXwCiqGvbQtCf3p8RIzTQ6s0j0UqiEdMcvVFspRFwIqOIp1kn+RfJ/3QwWx7L+dz+G TLZ5rfS2Mx3vXkIegwnG2FJmJNwFlzj0aE/nn7K/M2sL0+4MdeicagzPvCT43p5o5BEg P+OptutBbCJgeePZshGaEiG7RMbq/RZlmDmDvJll0nMbbqt0MIgXXKZt+/m3UY/9ahMv bHWA== X-Gm-Message-State: AOJu0Yzrtt8xNNkNjXATil185A/Uqvh2m4kSZj8akRC64VRCH4La2Chw 0ypO5VcvC1VUcLkk1wy+S6feHg1wwDb+gXQHhfhYnfny+rMZRJ02tRMNRUUKzQ== X-Gm-Gg: AfdE7cnnSnUmHbv7I1zhLA1v+mMT2HCyTx8yYsKq1m7u5BKZcPNywSlX5utK84lzy2N t9Unu2Gcl9DacqOoEcXzqpadWxqEEA6Fd5hzAoKSX5UPMXNNLDjD4NUHxSVNFajsxqIKZehuX/5 dt5oahm0W+Jev1/CYx9OvL0LcEEkIJQ5pG8j+i7flaX9fB2bV1zp7xg2SAW5I/4g54lKNrF6+4s fY1NSVve+nGK6diEpWyejIOa5YGXThO+lo6XLiYvZYiqM8uCKGXV5aJGXIiy9euEygMfy0kzB6W pDQLWgxybN0VTN++R28EDr0JcSQm7mw9jzKknU9FxHHvKBUtklsA6bAVLKjL4NfIXzdXJ+Tf4K0 BuKUq8mEUbLVpT3NOOx8lEDqTHeF9M7tWx00A6L/4qMnLVOBtGoIvJxqstuneFV+IdQdLogvVL+ /s+WgUP3cpCzIP/YIjJ9o8CziKNxkUB7V4MuLCeJknTQgmZdidhcypvwUkhnrd/fD6vs2E9G1xp PvzlKVBhshOGqoWXz3ntS9iOw== X-Received: by 2002:a05:600c:3b19:b0:495:48d7:f178 with SMTP id 5b1f17b1804b1-4954a3db76amr179216375e9.11.1784578307042; Mon, 20 Jul 2026 13:11:47 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , Bernhard Beschow , Bin Meng Subject: [PATCH v2 2/2] hw/sd/sdhci: Extract uSDHC-specific quirk Date: Mon, 20 Jul 2026 22:11:33 +0200 Message-ID: <20260720201133.24796-3-shentey@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260720201133.24796-1-shentey@gmail.com> References: <20260720201133.24796-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::336; envelope-from=shentey@gmail.com; helo=mail-wm1-x336.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: 1784578331215158500 Content-Type: text/plain; charset="utf-8" In Linux, the ESDHC_MIX_CTRL quirk 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 Reviewed-by: Bin Meng Signed-off-by: Bernhard Beschow --- 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