From patchwork Mon Jun 24 13:14:22 2024 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: 13709475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95DDFC3064D for ; Mon, 24 Jun 2024 13:18:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjX3-0001Lm-Ir; Mon, 24 Jun 2024 09:14:53 -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 1sLjX2-0001Ld-6p for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:14:52 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjX0-0004x3-Ke for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:14:51 -0400 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2ec5fad1984so15556521fa.0 for ; Mon, 24 Jun 2024 06:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234888; x=1719839688; 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=7mJMievbUPjRodtOESUjRxIX72igzigbVmP1VpcJ+Qs=; b=AyLzsuEvGwqKY+pNXiS6CKQuRD1FaJkYZ4FlJiCEg9DJss/XOAxVJix9cy8c41qifr J/obTuV8jwWhIRA3ONHYRWzTizYVGGfEbXj5716qV9Vxji7WPQSC9d3WYgYW6Gvmnvfa aY041ASuDB6KJfbASvDmZjeLt/Y6HzbF5iaPaJ6AGMNEmlP7qNiQt6y/p5wtbejrH1ih eiNXRJnV9ayr3+TkDw3JIcJGsWdgutyYJ0FAv+mTJk4olFERVqIsgyhFfFLtnE7MFTeA Q+L1sSTo+CGvIF5jQZWoV0ma6J61hL5RJvlHP9WHPfRM0ouFBbdRPP3aVsyjwvlmcvlF k2yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234888; x=1719839688; 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=7mJMievbUPjRodtOESUjRxIX72igzigbVmP1VpcJ+Qs=; b=MMoR5cAXprJKP91uLAoQu7OS5ZTUNFVWqsvyZlodCEPoDcasOnnCrJU/1ugFTv2y7w 4Tzg+6hSZIg8kmd3qRR79w3zkm3Gv3RdQIg1Ddx9t9eb9dnPVloCc/A2hfX1gx51sQ0J xcEc0p7aMT+78Wk03xKrIF2u3VudR9gh75h+ug+GhFrLT/HYUy8vsb3IHDdY74lXomNg CGFpVEmrKdHEFpwBuX3Q7amiuEAfSDTBzKKR7/bMbveR/FFTT/SPKZz42cGTSKesYDna qMVeyp3vp+UgmyVLhr9JVtpurumUZhECGGoQef/1O9X9z54qq9BBEL/Z98uLE3IPzy6o aIqg== X-Gm-Message-State: AOJu0YzSQwscAboFnzuPsglkbIzj5E6a+v/h08hIt02HjhtMIa8xjVWm EIawNV2JnAAo9A8urAQntRJCKYvdMYg7LJdHbw4AfisTe7M2g4oLcr1GaoRGq3yefI+JrtG2BAp P X-Google-Smtp-Source: AGHT+IFKSUCwbyug4dt9nWTfDpOjGVqMwCw2DrgQgUvfZxUzt20BuZeIWNOSINyKNPWnUN8YsDyrwA== X-Received: by 2002:a2e:918a:0:b0:2ec:4086:ea66 with SMTP id 38308e7fff4ca-2ec5b2fc27bmr38710701fa.4.1719234888511; Mon, 24 Jun 2024 06:14:48 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3663ada0bdesm10021016f8f.113.2024.06.24.06.14.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:14:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Richard Henderson Subject: [PULL 01/19] bswap: Add st24_be_p() to store 24 bits in big-endian order Date: Mon, 24 Jun 2024 15:14:22 +0200 Message-ID: <20240624131440.81111-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=philmd@linaro.org; helo=mail-lj1-x235.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Commit 14180d6221 ("bswap: Add the ability to store to an unaligned 24 bit field") added st24_le_p() for little endianness, add st24_be_p() equivalent for bit one. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Richard Henderson Message-Id: <20240621075607.17902-1-philmd@linaro.org> --- include/qemu/bswap.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index bd67468e5e..ad22910a5d 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -38,12 +38,14 @@ static inline void bswap64s(uint64_t *s) #if HOST_BIG_ENDIAN #define be_bswap(v, size) (v) #define le_bswap(v, size) glue(__builtin_bswap, size)(v) +#define be_bswap24(v) (v) #define le_bswap24(v) bswap24(v) #define be_bswaps(v, size) #define le_bswaps(p, size) \ do { *p = glue(__builtin_bswap, size)(*p); } while (0) #else #define le_bswap(v, size) (v) +#define be_bswap24(v) bswap24(v) #define le_bswap24(v) (v) #define be_bswap(v, size) glue(__builtin_bswap, size)(v) #define le_bswaps(v, size) @@ -357,6 +359,11 @@ static inline void stw_be_p(void *ptr, uint16_t v) stw_he_p(ptr, be_bswap(v, 16)); } +static inline void st24_be_p(void *ptr, uint32_t v) +{ + st24_he_p(ptr, be_bswap24(v)); +} + static inline void stl_be_p(void *ptr, uint32_t v) { stl_he_p(ptr, be_bswap(v, 32)); From patchwork Mon Jun 24 13:14:23 2024 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: 13709476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B45AEC2BD09 for ; Mon, 24 Jun 2024 13:18:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXA-0001QL-1g; Mon, 24 Jun 2024 09:15:00 -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 1sLjX8-0001Mo-BR for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:14:58 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjX6-0004yd-Dj for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:14:58 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4217990f8baso37997685e9.2 for ; Mon, 24 Jun 2024 06:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234894; x=1719839694; 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=aSK8hO4sLlN1hU/1KYxtFOH8CJir4+Yl/Ws4QmLQZLA=; b=upOoYYP9Vsy5BRy55w+Egr7n6iTSPcyii49ZI9cECZIr7UYB4jX4K9fRJKquQ7dH4l Lv7GZ082QeVTDCHKLxvO7R6MhR6zU++xlefFmfsIgml/TMXzhCU4lFKNYa+LDA6K8lWX Hg4ugob2kVrL4EDc8F65TsZ6+1xxTw0d8Omp7zd9psdTI9Z6OnebaDnQW1lVrPxsfPj2 MmcMiD4xQrDErVztytfU1fdTLbBjmrL8Dxt6dwr8Ip99PEqMnPsBPNY9tT089xO9ie56 q+YORExKpOR9g/thnBQjiwfoURbtmJNZC6LEZMg8W4D2/rHfzMlnXjfL+XSrzn26ZxYu 7OsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234894; x=1719839694; 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=aSK8hO4sLlN1hU/1KYxtFOH8CJir4+Yl/Ws4QmLQZLA=; b=IWWiuT1z4bFEmZm4EnkTfwGN9ebqIPcD1p/8Q4kcbIE1ljPZ6VF01FYIfkyQQl7r2N u1IyIkU90SprB5zewLgp1+aA3TP87lJK3W3f0MHo8u0OcbkCxhLx9UOlU74MAuwlDQnS 5Ip/T+sqCSCY+1DxLjAAJWm7bmBzBopp1gfGr+rX3IGZU5I8mxNSs6d1DDvz/lGe58gb 3mUow2fxZmBXC1XorkEV4S8u+Yy5/8a4lGG1/XT2PUiMedAn7ybh6uomLLVfGTK0wVuz bQE3o4quYvQV8YGkCZlba+Y6OyH8A9EeiiJE+BjyJoTJi4GsAf7YhUAcsJpxA5WFIk4/ J78Q== X-Gm-Message-State: AOJu0YwmgGcoTsMNzZ8Q+ziZua8FMu433JQYajuP2ckDqP79qJx2pHE/ wYsumSlE2Sa5h/7sUujoKxRl68fyftoIz6nfo/9KXTift58gGKyMNeO0c5l7fc+LlCRuU0e/Z+y 8 X-Google-Smtp-Source: AGHT+IG27lmH8c5acaDS4R9l0BvYew+nhI6n0YlO0kNThaUfJ3gCSxR5aBmqL6Y9iCbFddBOwirUlA== X-Received: by 2002:a05:600c:818:b0:422:1163:4488 with SMTP id 5b1f17b1804b1-4248b9c9c5dmr35020065e9.25.1719234894569; Mon, 24 Jun 2024 06:14:54 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247cf5272esm176765475e9.0.2024.06.24.06.14.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:14:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alexander Bulekov Subject: [PULL 02/19] hw/sd/sdcard: Avoid OOB in sd_read_byte() during unexpected CMD switch Date: Mon, 24 Jun 2024 15:14:23 +0200 Message-ID: <20240624131440.81111-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org For multi-bytes commands, our implementation uses the @data_start and @data_offset fields to track byte access. We initialize the command start/offset in buffer once. Malicious guest might abuse by switching command while staying in the 'transfer' state, switching command buffer size, and our implementation can access out of buffer boundary. For example, CMD17 (READ_SINGLE_BLOCK) allows to read up to 512 bytes, and CMD13 (SEND_STATUS) up to 64 bytes. By switching from CMD17 to CMD13 (see reproducer below), bytes [64-511] are out of the 'status' buffer. Our implementation return R0 status code for unexpected commands. Such in-transaction command switch is unexpected and returns R0. This is a good place to reset the start/offset fields to avoid malicious accesses. Can be reproduced running: $ export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 $ cat << EOF | qemu-system-i386 \ -display none -nographic \ -machine accel=qtest -m 512M \ -nodefaults \ -device sdhci-pci,sd-spec-version=3 \ -device sd-card,drive=mydrive \ -drive if=none,index=0,file=null-co://,format=raw,id=mydrive \ -qtest stdio -trace sd\* -trace -sdbus_read outl 0xcf8 0x80001010 outl 0xcfc 0xe0000000 outl 0xcf8 0x80001004 outw 0xcfc 0x02 write 0xe000002c 0x1 0x05 write 0xe000000f 0x1 0x37 write 0xe000000a 0x1 0x01 write 0xe000000f 0x1 0x29 write 0xe000000f 0x1 0x02 write 0xe000000f 0x1 0x03 write 0xe000000c 0x1 0x32 write 0xe000000f 0x1 0x06 write 0xe0000005 0x1 0x01 write 0xe0000007 0x1 0x01 write 0xe0000003 0x1 0x00 write 0xe000000f 0x1 0x11 write 0xe000002a 0x1 0x01 write 0xe000002a 0x1 0x02 write 0xe000000f 0x1 0x0d write 0xe000002a 0x1 0x01 write 0xe000002a 0x1 0x02 EOF hw/sd/sd.c:1984:15: runtime error: index 256 out of bounds for type 'uint8_t [64]' #0 sd_read_byte hw/sd/sd.c:1984:15 #1 sdbus_read_data hw/sd/core.c:157:23 #2 sdhci_read_block_from_card hw/sd/sdhci.c:423:9 #3 sdhci_blkgap_write hw/sd/sdhci.c:1074:13 #4 sdhci_write hw/sd/sdhci.c:1195:13 #5 memory_region_write_accessor softmmu/memory.c:492:5 #6 access_with_adjusted_size softmmu/memory.c:554:18 #7 memory_region_dispatch_write softmmu/memory.c #8 flatview_write_continue softmmu/physmem.c:2778:23 #9 flatview_write softmmu/physmem.c:2818:14 #10 address_space_write softmmu/physmem.c:2910:18 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior hw/sd/sd.c:1984:15 Reported-by: Alexander Bulekov Resolves: https://gitlab.com/qemu-project/qemu/-/issues/487 Buglink: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36240 Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20240408141717.66154-2-philmd@linaro.org> --- hw/sd/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 807b5d3de3..6a7a10501b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1826,6 +1826,13 @@ send_response: break; case sd_r0: + /* + * Invalid state transition, reset implementation + * fields to avoid OOB abuse. + */ + sd->data_start = 0; + sd->data_offset = 0; + /* fall-through */ case sd_illegal: rsplen = 0; break; From patchwork Mon Jun 24 13:14:24 2024 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: 13709473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67E21C2BD09 for ; Mon, 24 Jun 2024 13:17:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXH-0001WC-2j; Mon, 24 Jun 2024 09:15:07 -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 1sLjXE-0001VD-NJ for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:04 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXC-000506-5h for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:04 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ebeefb9a6eso47625211fa.1 for ; Mon, 24 Jun 2024 06:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234900; x=1719839700; 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=G5C/rBGUajz/uZ65x4moAAqa+NPc5S7yF9iilS4WUHk=; b=bQ4G3gE+VPTTgE7xHzMNoeYf92xWNXMWYVj2KrdoMFRsILwwyQkhm+JHZHScPISZty GyJ1tRYcU2bvLPg6XiC9Ap884zbLMXL6E6Otsqj0tGPXUnTBmfh5KeCViEX/7pTO6gN1 mYJA1Qh0qNkRMyQBcxiYLwlsI1AptKKb5EGRYpygtGM+ur6ISn4VtAZaKyu+slAPfcv9 FxImM925Tk0jjGYr2FaIW5TBAwB1T0q04FbGpl4TReG2DU1QSqMOppasw6dHRkguHPOF 7hUjV9T3hFFo19vcoxosQHSJa4eFoXaUJPQ+a7K2UbibrVb7kK7QQBAWPsjzKKNOGckI 89zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234900; x=1719839700; 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=G5C/rBGUajz/uZ65x4moAAqa+NPc5S7yF9iilS4WUHk=; b=GVg7D5hLy5wxk++ilYlpLvZ1YZb74/fiKRC/Rj7nP/4VxN1bW+0jHPZjDg9XR83xnW BGxSaQ94jXl0AAANRFatLbR+AgtuuqjguWom8NqZue1B04yVj3FFbMC3S6bABo1uimGp E83zO+XACxQrOLC5D/JeIplX/VTPCkeKy22PKpCgMN7cmJZRQZaO8mF6hmjD57XHO1fK zH6BnNCisLkAEeNBUvaDZben24yJXSS8SDEKzocgHOjMw1G36qZUQBHAILWCKpuvtjMN vO7/tpc+P2+EB/w8AVwsrGYFSXZr5mH6lNgi8MiYOcb5HwTrpEZj4OT/XKnLv2SjjGN/ OjJw== X-Gm-Message-State: AOJu0Yyo0pfK2IE4AIzrdY8XTcJAtSv+Wg4OM7oScWp3ODy5rYKS5t8B HaWeez/IngWs6i5B78sWg80mRCR9nkkRBx8HUj2FFTdo4wweR7r3wimcEWo1rQeOOKdXHGTYoPr t X-Google-Smtp-Source: AGHT+IELuqR4wMmlDqCMx98lY9cPeUbP8HZpgf6vJKFgGQ19UYoDv6DMwEaavXqWGwYmux4riJ1ICw== X-Received: by 2002:a05:651c:104f:b0:2eb:fb9c:5a85 with SMTP id 38308e7fff4ca-2ec5940087bmr28858911fa.23.1719234900175; Mon, 24 Jun 2024 06:15:00 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424817a9667sm132776375e9.15.2024.06.24.06.14.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:14:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 03/19] hw/sd/sdcard: Correct code indentation Date: Mon, 24 Jun 2024 15:14:24 +0200 Message-ID: <20240624131440.81111-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22a; envelope-from=philmd@linaro.org; helo=mail-lj1-x22a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Fix mis-alignment from commits 793d04f495 and 6380cd2052 ("Add sd_cmd_SEND_TUNING_BLOCK" and "Add sd_cmd_SET_BLOCK_COUNT"). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-2-philmd@linaro.org> --- hw/sd/sd.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6a7a10501b..ba7f165cb5 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1069,33 +1069,33 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { - if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - return sd_cmd_illegal(sd, req); - } + if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { + return sd_cmd_illegal(sd, req); + } - if (sd->state != sd_transfer_state) { - return sd_invalid_state_for_cmd(sd, req); - } + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } - sd->state = sd_sendingdata_state; - sd->data_offset = 0; + sd->state = sd_sendingdata_state; + sd->data_offset = 0; - return sd_r1; + return sd_r1; } static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) { - if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - return sd_cmd_illegal(sd, req); - } + if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { + return sd_cmd_illegal(sd, req); + } - if (sd->state != sd_transfer_state) { - return sd_invalid_state_for_cmd(sd, req); - } + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } - sd->multi_blk_cnt = req.arg; + sd->multi_blk_cnt = req.arg; - return sd_r1; + return sd_r1; } static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) From patchwork Mon Jun 24 13:14:25 2024 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: 13709461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53DBDC3064D for ; Mon, 24 Jun 2024 13:15:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXK-0001da-Kl; Mon, 24 Jun 2024 09:15:10 -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 1sLjXJ-0001cR-8K for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:09 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXH-0005CD-GL for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:08 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-362b32fbb3bso2930121f8f.2 for ; Mon, 24 Jun 2024 06:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234905; x=1719839705; 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=9AZo3Cd3b6HBjlscPz+JzsDxsvHUlQzRA2cgC5como0=; b=L1OZqC937Pj0hY6ez4EYhB7/WxrMeLvrkxZXm9rXtzWMmnpKWFVXmE5Z8FmWS0Hsal 7QB+E/Cax4imOGqhTVOzT3+e5gkwFpRDQ3gCbsJBPehkD9Tp+kHSa0J6Zzcg5SYX1TMT 2MMFfMwZ1YCr1U83fGfASOIjc01xWFhkt/c/JyhDZrbCc5vId2TXVMpyxQ7QXmpYTk4K cLm0s4fE8j0kRI7WOTtnzyYuItOp+WzqAxuZyPVQfHZbVZNWH1pH70lEBts25H51nkHa WpnpoPLKGQptaGHM/EHQXaeuvh6kyaoHpOsiKKvjZUYP2VDfSbOi3gzET4AvZHijnTvY aUUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234905; x=1719839705; 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=9AZo3Cd3b6HBjlscPz+JzsDxsvHUlQzRA2cgC5como0=; b=KxAja1OvsjaWuXI8EU6v+tNEn2hPuTZ8YwEgCBHc1bCx7L0s+I1J/v9BErRKRK+paV H3+xWbrI98HFR6Ikcn71mp+iHG2itJJTpiSbj+0JtAwIYP1nqgRsIz9ZGpmGpB0vPLQl 9PG/MvL3g3kJcUO5HxK0kPIeMQ0SaPBV4cK/2E2GqnP6gEbX1N/hj7ZMK6YrLjL4nlM4 jbevSkCQeOUFLOpL+dSs2AHkom9Z47f3L+QhpU96IlP9KAHISG8tm0VW7yEGffd+gzVn kMIxFbWVDjLbkvhrC8vKcK3dhHQP1yJbQcRn7LYESdJbg1mXDeJPI/dh+q5vIIK+iWr5 a4sw== X-Gm-Message-State: AOJu0YxBDoAy9fQPQDBB8qQcrtCKWdV3GOAw+G/K9ZwSHPa5lGr4oX2B SV/he2Mz0FEPnmBQ4pYCZExAR53pBuovSBv5ixSZjvW1R8Zb3U3UiI0tXrZxM3r+6PWp0hHJc+W p X-Google-Smtp-Source: AGHT+IG4znU+F6hcRsyW5NcF8rYNmjn2yjEHEUiElb3j6oXOd6VQsqV2LVAWQ1sODjUSG+37rMaQrw== X-Received: by 2002:a05:6000:154d:b0:366:e7b5:3b49 with SMTP id ffacd0b85a97d-366e7b540a8mr4645416f8f.54.1719234905753; Mon, 24 Jun 2024 06:15:05 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366387cf44asm9978938f8f.26.2024.06.24.06.15.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 04/19] hw/sd/sdcard: Rewrite sd_cmd_ALL_SEND_CID using switch case (CMD2) Date: Mon, 24 Jun 2024 15:14:25 +0200 Message-ID: <20240624131440.81111-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Keep this handler style in sync with other handlers by using a switch() case, which might become handy to handle other states. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-3-philmd@linaro.org> --- hw/sd/sd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ba7f165cb5..46388a140a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1044,13 +1044,13 @@ static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) { - if (sd->state != sd_ready_state) { + switch (sd->state) { + case sd_ready_state: + sd->state = sd_identification_state; + return sd_r2_i; + default: return sd_invalid_state_for_cmd(sd, req); } - - sd->state = sd_identification_state; - - return sd_r2_i; } static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) From patchwork Mon Jun 24 13:14:26 2024 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: 13709464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1230C2D0D1 for ; Mon, 24 Jun 2024 13:16:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXR-00021y-Bd; Mon, 24 Jun 2024 09:15:17 -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 1sLjXP-0001oB-Nr for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:15 -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 1sLjXM-0005DP-VJ for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:14 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42179dafd6bso31523655e9.0 for ; Mon, 24 Jun 2024 06:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234911; x=1719839711; 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=oLr6VQ/1L7wjwJ5K6EJixR6ZpMPokOVueWHu3KJVNLE=; b=Gd+IDBeEtCwFpt9748UgNVgPz215uNbMBHMrHDi2B3isOvIODAQZthQtsE0N2M6gV+ xaa9CICJdCvUHlGFlrKR82WJKk8Hjx7FwsyfMznVuH8vrM4X09sinG18IW5eAwRuSt8Z aGtW+qVT1f550pFVIzkWkiYiWVzU+frBS+x24wZW6f+NNP3WLwOGxJiUzbPLqhYCcWAL vj9DxCwGzscnpaSM/peUbTmtMlEmljm0IMh7Nx4ar07/enkPgUrAsL2rci/QTyuU+Xd6 0M+NxwXlwOGW9TjYel2IPI2utHbdhhjFrS3bhr1IbgrVV1+7d09K9RhLKUegVV7hOnEO cCUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234911; x=1719839711; 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=oLr6VQ/1L7wjwJ5K6EJixR6ZpMPokOVueWHu3KJVNLE=; b=u2E8g4JUIz29300zW6+YxCfAGArtw5nt16OkZN9e4ERtAhUasm40+wR/mxVejjIJ7T pDyM6AgcQycYy6o7IpmvsIkQA6Qe5zYVfttmfmiHQY12/Vr+S5JcxtKJbvCb+oPbVBuJ HS1AbQfXKm3bKW5npiYfhYTQ89Wb4iQpNyZf6iPDZ8t9AxpSff8XEUfWpXB3vzN7HIMo aJZaXCWcSGGaNirDF59AgaiVAZy+0gkU+bdLj17UYY7+eJ9PKtleePSnSNhapxALTgKQ 6k0wtGTU6IEEZ3FFlkD2f6D+QWy0KffqfoGaRjZQoPa4IXJwGvVmy5nrb/AniEb+jncB m9hw== X-Gm-Message-State: AOJu0Yznc3cN+L6amQ8cBzreRBYRbZPk4UXMegke9ooHWBdJDrPyXf9W 9YpUzPvV/lK4e0ooVpi3eBaavHhI7g5fxFHpUBySAKzl9F4re2I4lWp05TWxAtMs3QRuYhnAjQv B X-Google-Smtp-Source: AGHT+IF6YrxTnqSQiDWLmkLqvS4Q3W5r7PSkOZFQU0JP8gIcUjGvTQsHzYo29Kd93+VosrBug1hXWA== X-Received: by 2002:a05:600c:138e:b0:421:805f:ab3c with SMTP id 5b1f17b1804b1-42489533effmr55383735e9.14.1719234911131; Mon, 24 Jun 2024 06:15:11 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248191c5adsm133562855e9.39.2024.06.24.06.15.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:10 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 05/19] hw/sd/sdcard: Fix typo in SEND_OP_COND command name Date: Mon, 24 Jun 2024 15:14:26 +0200 Message-ID: <20240624131440.81111-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=philmd@linaro.org; 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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There is no SEND_OP_CMD but SEND_OP_COND. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-4-philmd@linaro.org> --- hw/sd/sd.c | 6 +++--- hw/sd/sdmmc-internal.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 46388a140a..72d71259d3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1035,7 +1035,7 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) return sd_is_spi(sd) ? sd_r1 : sd_r0; } -static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) +static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req) { sd->state = sd_transfer_state; @@ -2150,7 +2150,7 @@ static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { [0] = sd_cmd_GO_IDLE_STATE, - [1] = sd_cmd_SEND_OP_CMD, + [1] = spi_cmd_SEND_OP_COND, [2 ... 4] = sd_cmd_illegal, [5] = sd_cmd_illegal, [7] = sd_cmd_illegal, @@ -2160,7 +2160,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [6] = sd_cmd_unimplemented, - [41] = sd_cmd_SEND_OP_CMD, + [41] = spi_cmd_SEND_OP_COND, }, }; diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c index 8648a7808d..c1d5508ae6 100644 --- a/hw/sd/sdmmc-internal.c +++ b/hw/sd/sdmmc-internal.c @@ -14,7 +14,7 @@ const char *sd_cmd_name(uint8_t cmd) { static const char *cmd_abbrev[SDMMC_CMD_MAX] = { - [0] = "GO_IDLE_STATE", [1] = "SEND_OP_CMD", + [0] = "GO_IDLE_STATE", [1] = "SEND_OP_COND", [2] = "ALL_SEND_CID", [3] = "SEND_RELATIVE_ADDR", [4] = "SET_DSR", [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", From patchwork Mon Jun 24 13:14:27 2024 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: 13709462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6033EC2D0D1 for ; Mon, 24 Jun 2024 13:15:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXZ-0002JG-RQ; Mon, 24 Jun 2024 09:15:25 -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 1sLjXW-0002GK-0d for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:22 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXU-0005EN-BP for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:21 -0400 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2ebe40673d8so49021551fa.3 for ; Mon, 24 Jun 2024 06:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234917; x=1719839717; 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=cGq9CknDLxCzVytX4zHmuSLklJOyE1bcs9yCSxS9ogk=; b=CmaqscENhnn2kYiljC6eAO0ISCj2LFcmNolkxTeqx0/qXdk3qTjpKbOdw3GlHvu/2p 3vrCvOO4uVsx/lrsSqDWUWkw8P81BbvtDEy5b0GiZ0pK7BWd5R0N5mkCPgFkMTJMvXzo pi2OYWlkgvIJtf5GOwmtEfEhPSJeqHawfwvdgTY08Jvb2fYKvRi5tweV7eXnSJL3VvDG kZd+WXvj0r80o2Uc4PhALcv8YIZaG2fRFehPm58lni/2m/2KEQ4LuvsIMuRRwRnCLmU/ js2RJ04vOKVT3hLCISRw11ERJbWo0/oQRDrJanjTXuYmAzWRiRUmOyHVqK5IxKeiSfGy BMlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234917; x=1719839717; 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=cGq9CknDLxCzVytX4zHmuSLklJOyE1bcs9yCSxS9ogk=; b=uxEgZ/L3HO63I41dgdktPO5yp+O4JBjxTHEknLoAmGyDvy80Lpnvfk/l8mbjbPvNHh AI3NZtMxfnn5G12XPukmFK3kWFxyaxeNEzEjFnLyCqrGsmp98lYVOXiJQf0aEPhpNg4L JlOsp4RVxuNqfowtgKosWs1c7Ifi16OBJ+0B4gUeLlEYl1tmWJxrVrfwpnSbtEuhod+h S/x1gK6WaM6xJhMh8ma2oQODz/4HD6V793ahOeShF6JEloezRI72uyiDEHH5fc3wwfxq J36oBWRiudLUuQMbDYz+y3RagSAD0BOZ59kvBj47iVB3iqsGFVF9VhDOj/AiK5hiOC09 hx3Q== X-Gm-Message-State: AOJu0YykswFW4LDnF96ZDyHG3/D49V4BiEKupfNq2ETuPm7jz6fcpXng o1+3i+xhvCRQieOgcjgveU6nHHe0Cy6IyCbOJLU0o9umBK4FFloRUlasUdzBk4z2/eFHE0tOreS c X-Google-Smtp-Source: AGHT+IFpO2Ceup9ETQ0B85S4/kGSfjjAfkuNe62Hz037/LUOxezgwyoCtlNfXvN7cVDkYKXzOjjr7A== X-Received: by 2002:a2e:9e0d:0:b0:2ec:49c2:a79f with SMTP id 38308e7fff4ca-2ec5b388519mr25367741fa.42.1719234916739; Mon, 24 Jun 2024 06:15:16 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0bea05sm173281545e9.18.2024.06.24.06.15.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 06/19] hw/sd/sdcard: Use HWBLOCK_SHIFT definition instead of magic values Date: Mon, 24 Jun 2024 15:14:27 +0200 Message-ID: <20240624131440.81111-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=philmd@linaro.org; helo=mail-lj1-x235.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-5-philmd@linaro.org> --- hw/sd/sd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 72d71259d3..a14c5ff147 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -596,7 +596,7 @@ static void sd_reset(DeviceState *dev) } else { sect = 0; } - size = sect << 9; + size = sect << HWBLOCK_SHIFT; sect = sd_addr_to_wpnum(size) + 1; @@ -822,8 +822,8 @@ static void sd_erase(SDState *sd) if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { /* High capacity memory card: erase units are 512 byte blocks */ - erase_start *= 512; - erase_end *= 512; + erase_start <<= HWBLOCK_SHIFT; + erase_end <<= HWBLOCK_SHIFT; sdsc = false; } From patchwork Mon Jun 24 13:14:28 2024 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: 13709465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD884C2BD09 for ; Mon, 24 Jun 2024 13:16:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXm-0002Vw-AM; Mon, 24 Jun 2024 09:15:38 -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 1sLjXa-0002Li-K0 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:28 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXY-0005HY-UK for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:26 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52cd628f21cso3302778e87.3 for ; Mon, 24 Jun 2024 06:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234922; x=1719839722; 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=A3kIXqxbyj4EO+8ab6+OipvibcTKTQuRzHPmi/RkZhY=; b=g1TaVrMvsOlIOrBgoZw4ZNXRvilrw2b9lVbFQFqf4gji8sN/iiOL4oRQyNewKNVUx7 8RqseZJDqxMcnl8XvBu/cEm3xXXb1PBBSVCvo4lMfYiogPCFt2eJv025cnQPVcwRcyRx WZl7Bz0VAoVkKbVVTfr8Q94hAhXLPZlxcFveshFAoCgqod/daqGCkiBUP1LjgaNxZBL0 G6fvKB7ugBpzjBvSJCAOA4KJGkiAs1bZpytA4UHhR10TkY3AmS2UnwptfN6TZM07BJjt kglTYEJCrWsCOMpgV6XqfiGklfuNwWO3usgNp6d+bCJBzQLiyXzBFXGSTrnX0hHRP0W+ nYGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234922; x=1719839722; 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=A3kIXqxbyj4EO+8ab6+OipvibcTKTQuRzHPmi/RkZhY=; b=VXMxTKIA2nUMoR4xi/bDkHwZoksoMZm+AIsgAFlfrizxjmqd3caFvPIYkwyNL4t5s1 mOmVnJDHPZQ3n0VLACpEubIg4Y7fvYpDkEy05DJqkWGP5sKi7awaomLdDgVQ9dmwPr+Z alZH27V2enoDlPjaI7fsCFRvtEojtqDcV0+Sb8c6BZjiCnJe5xllxWyl/YDJSCbDb/xb xbuvheBoOqVHAvzCat2feonT8kVQVVNx5sF37oWC3mR4SVp3RO2JR3v8aPxSNhJAYIrB UTXiimX3gtxn9525mfi7PK7JnnJHg73B60MIWHsDzZLLYGh1Vw4YDQYD+e8QeKhXIwjJ 3kXQ== X-Gm-Message-State: AOJu0YzytvjpT/tE3jZnDXA9ErmAPZ3VdxGUCP4upOfe/+BWBlo6vAji 0rtw2gYemwFx3axttHnHqMXX3FWQO5tZClGm+W+VlKDTdNoVHr8QGUw/r+Q8//IKEyUpQc1RC2I X X-Google-Smtp-Source: AGHT+IEc2PsUM5CjYLN1s5ACKJ1yrZtiZhRYueq+WV//jL7bJXWgZ1GHNeX4BRss9iMnBP/a3vWPVA== X-Received: by 2002:a19:911e:0:b0:52c:de9e:194 with SMTP id 2adb3069b0e04-52ce1835b48mr2368094e87.28.1719234922215; Mon, 24 Jun 2024 06:15:22 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366ed18dfeesm4046705f8f.93.2024.06.24.06.15.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 07/19] hw/sd/sdcard: Use registerfield CSR::CURRENT_STATE definition Date: Mon, 24 Jun 2024 15:14:28 +0200 Message-ID: <20240624131440.81111-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=philmd@linaro.org; helo=mail-lf1-x133.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use registerfield-generated definitions to update card_status. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-6-philmd@linaro.org> --- hw/sd/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a14c5ff147..64270dec0f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1788,8 +1788,8 @@ int sd_do_command(SDState *sd, SDRequest *req, * (Do this now so they appear in r1 responses.) */ sd->current_cmd = req->cmd; - sd->card_status &= ~CURRENT_STATE; - sd->card_status |= (last_state << 9); + sd->card_status = FIELD_DP32(sd->card_status, CSR, + CURRENT_STATE, last_state); } send_response: From patchwork Mon Jun 24 13:14:29 2024 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: 13709479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16001C2D0D1 for ; Mon, 24 Jun 2024 13:19:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXr-0002c4-SH; Mon, 24 Jun 2024 09:15:43 -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 1sLjXf-0002Tp-Ua for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:32 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXe-0005LN-9P for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:31 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-421cd1e5f93so32928525e9.0 for ; Mon, 24 Jun 2024 06:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234927; x=1719839727; 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=RqlOEyj+8xJJtMHox3KeLzXAnw9eaudtpJH6jXIsYOM=; b=w0e55R1jxQgPIHzVaV8IuY/CBhxuRl9AU+O7IwifzRNR3XHo2LxmK2r3qx103Ot2Ez J6jMXIlUSP0OZKyTy5fEXo69zPdklwb8jni5l/7DNffh3sQ1lH3F5f0w0a6IYk71c6Vs kBDXhRrTEdgprWDipP7WXgL2v2CIyZVBcYOl1ZyPTfpgwleiFHWVBd3aE/NwyB7rxQE9 TomomL3lxNLukEC1OI179MXjhDnVWM+fd3BkR4c1+iTEttYnhhDyZgk1aZN+5LoL3rVH Z7yNuZqV1jIGQFQkXHobCB5+gQdK1XcAhAsKzoAHEHI4LvNL1MCbqDxwYGWuz7THobNd olEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234927; x=1719839727; 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=RqlOEyj+8xJJtMHox3KeLzXAnw9eaudtpJH6jXIsYOM=; b=f5gtK1oSxYfsY/AymIVXtNieF7tPqworGcz3lXYYLJOJ0UTqqpF7xBXUV1uTgStTXc Bp84Xiz+tGN/89qLLxnXtg396mdyhtqRJHucZdCuNs38AgGOjLiURXfpZsWo6QAXmDZB 9EJI/WxSWFO7SU5opjbbaGWtIzkDMzsbSNbGnst/OPs5KuDH5yljJyakGAQ366F/HAzL 2AOUseYN2wZTbKoeLMkcf27SfYrlzFB8FuLenbMdFwbNDMRZex7xJ9uCCXRdSrDG/CMx vhYPshall2xMudRnu6k8U+JSJPpRMryCFpvQ4XE6S4SbQQsYSr/0au22aMdHpJPEeJ8M KlHg== X-Gm-Message-State: AOJu0YyAXDNQuHi0hjsSQsG7lpsRblonjrooae/eRsVsh6u9gJplGHjq AosDWwd7J/7o2lhpV46pleEKAbPRqEMLjrpm9srmPuOh6Aifo7Jt2As7I03HE1CtSEoQnk//1RV g X-Google-Smtp-Source: AGHT+IFsGfWXVlKYx1jXjut4nYsav94FY1kOlHlNu6rHSUcoaGHmH89Sv1fd8lDZH79ER3hC9L0ijg== X-Received: by 2002:a05:600c:354a:b0:420:ffe3:8536 with SMTP id 5b1f17b1804b1-4248cc66a8emr36771655e9.37.1719234927498; Mon, 24 Jun 2024 06:15:27 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248191c5adsm133571485e9.39.2024.06.24.06.15.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 08/19] hw/sd/sdcard: Use Load/Store API to fill some CID/CSD registers Date: Mon, 24 Jun 2024 15:14:29 +0200 Message-ID: <20240624131440.81111-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The ld/st API helps noticing CID or CSD bytes refer to the same field. Multi-bytes fields are stored MSB first in CID / CSD. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-7-philmd@linaro.org> --- hw/sd/sd.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 64270dec0f..6e346e28ca 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -393,10 +393,7 @@ static void sd_set_cid(SDState *sd) sd->cid[6] = PNM[3]; sd->cid[7] = PNM[4]; sd->cid[8] = PRV; /* Fake product revision (PRV) */ - sd->cid[9] = 0xde; /* Fake serial number (PSN) */ - sd->cid[10] = 0xad; - sd->cid[11] = 0xbe; - sd->cid[12] = 0xef; + stl_be_p(&sd->cid[9], 0xdeadbeef); /* Fake serial number (PSN) */ sd->cid[13] = 0x00 | /* Manufacture date (MDT) */ ((MDT_YR - 2000) / 10); sd->cid[14] = ((MDT_YR % 10) << 4) | MDT_MON; @@ -462,9 +459,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[4] = 0x5b; sd->csd[5] = 0x59; sd->csd[6] = 0x00; - sd->csd[7] = (size >> 16) & 0xff; - sd->csd[8] = (size >> 8) & 0xff; - sd->csd[9] = (size & 0xff); + st24_be_p(&sd->csd[7], size); sd->csd[10] = 0x7f; sd->csd[11] = 0x80; sd->csd[12] = 0x0a; From patchwork Mon Jun 24 13:14:30 2024 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: 13709482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DADF3C2BD09 for ; Mon, 24 Jun 2024 13:19:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXt-0002iI-N8; Mon, 24 Jun 2024 09:15:45 -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 1sLjXk-0002Wm-IG for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:38 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXj-0005Pf-0z for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:36 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-362b32fbb3bso2930488f8f.2 for ; Mon, 24 Jun 2024 06:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234933; x=1719839733; 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=Te+GIxXW5gxfuWRPules7rOyRScrC1BJa4kjtT/0R0c=; b=EcW/XXJF+iN5ouAe7RWaQicBoYHFZj3RWCaz5nAgCtl+4mBKv1QjL1czSvuZtaCf2x mXEOW7sMhx+jFpIdbJrvm1bKiXsbcTJEOl5wkGxGLkpSlp6gzsV4YAIqR6NqUbKfBWoi f7YdUx3bXZzYpg17/cvIrEpPd9uLKOgW34HeFfYx5dpWE4e+Yk1hYuRlDD9d+AGYZTTu +rQ2PNxGK0FARe//K9HrOM29szC0005cM3Gl3zDZV4+1QZtcaehHxAD/G85uL0IVu8zf HHdkWPIwP9uDECxJ70SEmzOHBG6F83S1RKD+yKOT+R1HWeRpPwpESrdOglKq06QSn9WV M/Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234933; x=1719839733; 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=Te+GIxXW5gxfuWRPules7rOyRScrC1BJa4kjtT/0R0c=; b=KPNaStrdW9SPDwASSvv2X78zllXamNZeKuOWICymMFgJdhRoLwZke0B4KhJzWCakUa lE9N/rY1HfmqKP/7rJp+eyaPh8bL5vHz62gM+CagIOWa46xE86KwMOc+0jkjr3/VjWGg d5C1fyepsuEcKq269lugPV9+aTMDZVwfC/w5EkfxPjmO/9Ffn/EFNeQs4EG7zsoekbqr 2tnbnu9IMN+mwP9cT8ZVJKrAMfwk7m6aAkP9obWvIv+HtWVFmBoGsy03MSCcmRKsB1Ij O4lvQeR8nHupbBkueG0A2tl3VE48b4nJ8Q/XFm8wB/vdlGpg01C5RYNmCT1mAHI4DAYl yWBg== X-Gm-Message-State: AOJu0YxTPcerKtdMoGa9PyBF6Xj24nrfBUlpa7YOmzDXxDpvUasM6JBJ MmSmA2GlknmEL0aMcNTNoczWCRNSO72yE363eARuZdJkVALU17H6DgNGOXme51WnHyhrkeDm5TO 8 X-Google-Smtp-Source: AGHT+IH6toEszfWTYfOKgCh9I2fmxLt20QYVDKJ7HQVNVoi5h4sWO0/cOZ+E6wYKJF+5qP1VkOoOYg== X-Received: by 2002:adf:f610:0:b0:362:bb3e:93da with SMTP id ffacd0b85a97d-366e7a637e1mr3579520f8f.62.1719234932841; Mon, 24 Jun 2024 06:15:32 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36638301cffsm10046735f8f.10.2024.06.24.06.15.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 09/19] hw/sd/sdcard: Remove ACMD6 handler for SPI mode Date: Mon, 24 Jun 2024 15:14:30 +0200 Message-ID: <20240624131440.81111-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There is no ACMD6 command in SPI mode, remove the pointless handler introduced in commit 946897ce18 ("sdcard: handles more commands in SPI mode"). Keep sd_cmd_unimplemented() since we'll reuse it later. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-8-philmd@linaro.org> --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6e346e28ca..08a6d0aff8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1012,6 +1012,7 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) } /* Commands that are recognised but not yet implemented. */ +__attribute__((unused)) static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) { qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n", @@ -2154,7 +2155,6 @@ static const SDProto sd_proto_spi = { [52 ... 54] = sd_cmd_illegal, }, .acmd = { - [6] = sd_cmd_unimplemented, [41] = spi_cmd_SEND_OP_COND, }, }; From patchwork Mon Jun 24 13:14:31 2024 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: 13709469 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 207D6C2D0D1 for ; Mon, 24 Jun 2024 13:17:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXv-0002if-Bb; Mon, 24 Jun 2024 09:15:47 -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 1sLjXp-0002Zp-Pf for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:43 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXo-0005TC-2y for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:41 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42172ed3487so32262695e9.0 for ; Mon, 24 Jun 2024 06:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234938; x=1719839738; 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=HxQAYADKfbhpE1hUX1tIATqcZpfO3HwJuZqR6r1E18w=; b=trNSHaPgnX4IaVip/hUksNO34idS2zor3C73sUoOxui5ToLnr5dwCPwfLPGVYYmhbi +pmxwL+8PXyHu0xEL9Hz1H27lEXbb3YAVso33gH93gQ9YM6tDIrjA+z1pLpSAOQz5w+/ cggP5Vf0aT1i4WQMAvCtbfpNQID+mXayTTJEU9YXN1vrP/QsqWWocEU9L4qE3upRHecm fZZNJiQC1Gpg57ux5sRJvXfykcq/IHY9viTklOacRDCJUCa/+B4QP8qRQzwoUfEUyBPR A8b3UxOQdy9AVOLJ4lNxc9pCLKf8m03h6vr8PAU1OEe0pES892y1cROnahpb/PWq9Z0w bm9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234938; x=1719839738; 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=HxQAYADKfbhpE1hUX1tIATqcZpfO3HwJuZqR6r1E18w=; b=n20sWrj78esjAuE0hZHX/wEPnjI+dhhLYOlrivP/v+EeMWklb+lYvP+JNsumfPjoc7 xowJFcJ0FTSHwSmygmtBdRpju8BMhYisaUOQWPKGHNZfmpntttMSXzahuBOBVWms6Vm0 H8r4WQaBXAgUT1JrhyNnn+rZ6yqkIqmxAV6rYxFyR9cIyQB8/hS2L5QBvRMqJpkdSpA5 N1GNivO1kfrZiRPqCrVu5Jd3mbadETB2UJC8E6ch0NhVfT5VMBurBRu6kyEXFi6VBQuE eDwMqUi0HDD9cQhkDM43zji1Lqw7fBkHfmS+/Mk1tMp5d7Rwz7LP2SHbtRywFzlugB4s lWwQ== X-Gm-Message-State: AOJu0YzfbL/WrUh+gYrh+WYC9+KvWltnDX+mJiPwPzCtk7KCZO3b28Bs McG1fDdEmSopnso54ieyQ1QsvLO2bsOHhm0LGh5gufef/JLehmMTQkAbpOTgOmlK7EAPLzSc6EM r X-Google-Smtp-Source: AGHT+IHSMa+DmdpNjV5w300ZJgJlatZAoa6tIbFMsUeN8M86ygBiNCh4tV9oLT2NVnZydpjdwZUw6w== X-Received: by 2002:a05:600c:3225:b0:421:9fc4:7490 with SMTP id 5b1f17b1804b1-42489e3a9a0mr40156845e9.11.1719234938135; Mon, 24 Jun 2024 06:15:38 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42481921f16sm133394085e9.41.2024.06.24.06.15.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 10/19] hw/sd/sdcard: Remove explicit entries for illegal commands Date: Mon, 24 Jun 2024 15:14:31 +0200 Message-ID: <20240624131440.81111-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org NULL handler is already handled as illegal, no need to duplicate (that keeps this array simpler to maintain). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-9-philmd@linaro.org> --- hw/sd/sd.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 08a6d0aff8..4afb6988c7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2147,12 +2147,6 @@ static const SDProto sd_proto_spi = { .cmd = { [0] = sd_cmd_GO_IDLE_STATE, [1] = spi_cmd_SEND_OP_COND, - [2 ... 4] = sd_cmd_illegal, - [5] = sd_cmd_illegal, - [7] = sd_cmd_illegal, - [15] = sd_cmd_illegal, - [26] = sd_cmd_illegal, - [52 ... 54] = sd_cmd_illegal, }, .acmd = { [41] = spi_cmd_SEND_OP_COND, @@ -2163,15 +2157,10 @@ static const SDProto sd_proto_sd = { .name = "SD", .cmd = { [0] = sd_cmd_GO_IDLE_STATE, - [1] = sd_cmd_illegal, [2] = sd_cmd_ALL_SEND_CID, [3] = sd_cmd_SEND_RELATIVE_ADDR, - [5] = sd_cmd_illegal, [19] = sd_cmd_SEND_TUNING_BLOCK, [23] = sd_cmd_SET_BLOCK_COUNT, - [52 ... 54] = sd_cmd_illegal, - [58] = sd_cmd_illegal, - [59] = sd_cmd_illegal, }, }; From patchwork Mon Jun 24 13:14:32 2024 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: 13709463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74401C2BD09 for ; Mon, 24 Jun 2024 13:15:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjXx-0002rX-Rp; Mon, 24 Jun 2024 09:15:49 -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 1sLjXw-0002mq-Bc for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:48 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXu-0005Vf-Jn for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:48 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3620ee2cdf7so2765564f8f.3 for ; Mon, 24 Jun 2024 06:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234943; x=1719839743; 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=OJnTXjeu6vchkfoyUhTtN0woxxCm+FO3y7c+ViS30WY=; b=iq5bvPnE7yPZW80eNVcyaJ1HBiMh51MaGmzBaLCpCNLEG/momRb4++LBnxHEXpNY83 qrKfXVzDUzWfxcwBI2cN1SrN1XZK8+kBeFX+Ov8S3T85bYM4LJWUrMJ7gZimX9gQ5AjR IWAUZxY77StPAM2qfcGMkNRoOzZUHBMJRowQot8mzPh/5kEWy/wrN2twrhkgp5Hv8LQm qHK2z7szBPeKL0/U0RKbmduGOMHe3BYsjJFkgxqd0w7vUUYEWknK5Z7EJNyh8mQ3uK8E TY3S6qyZrydBqXXBu4srjDPbqKiUGcpfStUDl+w3E7Nf507cLuWggB7rAEZHTjH6QsaR tamw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234943; x=1719839743; 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=OJnTXjeu6vchkfoyUhTtN0woxxCm+FO3y7c+ViS30WY=; b=jAqP0V4DhpC8v7fs5Quzfr1BBsAkwEwiUDoqsLEv2wHPekVGRePIpCg7gVPaWOONY2 bZy9TaLCRX5aygCiH4vJNlmc8u2EEzc3d5cVNGM3X5sZumt7ES/Nnt4gaLaovZUajq5U uYIP0FGzEgoII/j5SFmy/A/T+cPrEUafUU0KIwM8cvruShlFjnD3t6LckA/BTf8KGC6d G8+mfaju7ygLogDAFVIVQm0LC48cEnM16dvvVnAYTdWlMiln/5cH5s6KSLQnEPfn8vPF tyXX6vtypM9FH5E/AVomWzoiqNlghbLPRRCF9LCP7RKpktBFw1MV58VivXtHZcUyRlLH EKJQ== X-Gm-Message-State: AOJu0YxlA+y/T67liDjss/iCVhpLquaetTyn3irYXXqnVou0nIO0iTiJ tRemIis0btRSPqoyf6dz5153Wlgo1p8Yi3BQt6ogPIMDdws9ec64PdHJhzhxTqNme5nuY3UjJb6 7 X-Google-Smtp-Source: AGHT+IHKiL8/JlR3ZqxBvaXv3FsPYbL/BdthKxrld0PwwrufKdXyBNxKU7ehSKrn/LKc4Sg8JUc7rw== X-Received: by 2002:a5d:5f48:0:b0:366:e90f:3758 with SMTP id ffacd0b85a97d-366e90f38b2mr3986933f8f.10.1719234943421; Mon, 24 Jun 2024 06:15:43 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366ea4c0d9dsm5018823f8f.0.2024.06.24.06.15.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 11/19] hw/sd/sdcard: Trace update of block count (CMD23) Date: Mon, 24 Jun 2024 15:14:32 +0200 Message-ID: <20240624131440.81111-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=philmd@linaro.org; helo=mail-wr1-x433.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-12-philmd@linaro.org> --- hw/sd/sd.c | 1 + hw/sd/trace-events | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4afb6988c7..44225bae9b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1090,6 +1090,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) } sd->multi_blk_cnt = req.arg; + trace_sdcard_set_block_count(sd->multi_blk_cnt); return sd_r1; } diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 94a00557b2..724365efc3 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -43,7 +43,8 @@ sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" sdcard_powerup(void) "" sdcard_inquiry_cmd41(void) "" sdcard_reset(void) "" -sdcard_set_blocklen(uint16_t length) "0x%03x" +sdcard_set_blocklen(uint16_t length) "block len 0x%03x" +sdcard_set_block_count(uint32_t cnt) "block cnt 0x%"PRIx32 sdcard_inserted(bool readonly) "read_only: %u" sdcard_ejected(void) "" sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 From patchwork Mon Jun 24 13:14:33 2024 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: 13709467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9F4CC2BD09 for ; Mon, 24 Jun 2024 13:16:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjY2-0003Fm-Aq; Mon, 24 Jun 2024 09:15: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 1sLjY0-00031Y-6y for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:52 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjXy-0005Wr-Ju for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:51 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4249196a361so6725015e9.0 for ; Mon, 24 Jun 2024 06:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234949; x=1719839749; 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=DdZdPflGxnU9+ulU0ghp7a6tzZgDef0bM1QxWZe/c5Y=; b=kkgm4+ajCkOKNAuFarhMNdjDKQo1TAN09CQdAt06qAKOJVzbHJp7mhgcKvCefjFkJd ylMWs89fjow63WlaoufzDas4HeWu8n8QLp2p/B9Z2ZnWHdtxmHYcKldba7co4sAqNTGs GG8efpvGN8tyAIwAjtLNWt6XzMXNleh2l5xag1RWZC/fqUirCFZ6aohncyDyHOsFNqKC fxZvAyfLkKQBLF5GUsrn+Rt65kT1OBuUhSu3BhsQMSiO73QYO6lsw0X2i7ot7qYP6+KG MPz80+i6ut9LN0ijm0A0U442pwiniZKrvKU97mRqZOcmBhy9tBAA4godfuy0rGc9tzYQ syjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234949; x=1719839749; 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=DdZdPflGxnU9+ulU0ghp7a6tzZgDef0bM1QxWZe/c5Y=; b=r5+Zd+eaETuOGuD0K3ZawCOEGmLDa2Yz6/UiH2go/6DKs64Kt7Ep67Axz93Jly+W+e IVFFXuRqE2nCEYufmMKcHvw1FMetA7G9N4Zd8LLLD55kMONyd1Ancqd385IDBCs0fJqe uMAeIoR/CFz8+6yztaRWDJkUo9/d45HF3iM0FW/C/1n5oijLF+Z9bb1/+4+nZi5GsblL 5fCSNCcjEN6L79DO49hI7kEssVt04OuboGQfO0tPKg7Hk53aJXHBsPI3YKsKHzvoCWlj mBouvETM1qO5TtegUcVQ3NwpRlwK+Ch/9wavShivV2XrpfZeMUHFiNsRJer2XmIksRkH AFjQ== X-Gm-Message-State: AOJu0YwzTW4f2gxQ82Yai59YjuOCBX/aPxVKMqANvpKBvA2uhankbwAH MWAVcbmU71cw8CoauiYRIPbWf/sUP50AHE6tVTdDcbXcl7K2njqHWAU+pYGaWR+fHREpECZ5YF/ L X-Google-Smtp-Source: AGHT+IG08VHolRJbigqqgPAxjYP492jniy9OjguFF6SbR+ZxNeWsrb64BRgcQQXTccA6H/ogpOdleQ== X-Received: by 2002:a05:600c:4fc9:b0:422:7c50:18ff with SMTP id 5b1f17b1804b1-4248cc66677mr29054385e9.39.1719234948767; Mon, 24 Jun 2024 06:15:48 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248179d3afsm140585865e9.5.2024.06.24.06.15.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 12/19] hw/sd/sdcard: Have cmd_valid_while_locked() return a boolean value Date: Mon, 24 Jun 2024 15:14:33 +0200 Message-ID: <20240624131440.81111-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-14-philmd@linaro.org> --- hw/sd/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 44225bae9b..04b141784b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1717,7 +1717,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, return sd_illegal; } -static int cmd_valid_while_locked(SDState *sd, const uint8_t cmd) +static bool cmd_valid_while_locked(SDState *sd, unsigned cmd) { /* Valid commands in locked state: * basic class (0) @@ -1731,7 +1731,7 @@ static int cmd_valid_while_locked(SDState *sd, const uint8_t cmd) return cmd == 41 || cmd == 42; } if (cmd == 16 || cmd == 55) { - return 1; + return true; } return sd_cmd_class[cmd] == 0 || sd_cmd_class[cmd] == 7; } From patchwork Mon Jun 24 13:14:34 2024 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: 13709470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C3B3C2BD09 for ; Mon, 24 Jun 2024 13:17:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjY8-0003rH-LW; Mon, 24 Jun 2024 09:16:00 -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 1sLjY6-0003cn-J9 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:58 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjY4-0005Xp-RR for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:15:58 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-362b32fbb3bso2930738f8f.2 for ; Mon, 24 Jun 2024 06:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234954; x=1719839754; 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=BZMgxVGycu8UCR6fk1Qn9uFvwvmJUGQDSX4skzfq58o=; b=Rah9nWw2jGg1E+C1rBbVQZHvJLAh1e6p7iCmnftlRMR+azz99L3OkhRmJ+2/NxV4iq fCR27sWYfQ/ok++U3TZiI832pyJ3U5RRTC92RntVXNQRScpBzy83WJMwbbfhrCHT5GAa ubbvdbcrvIwVXo6G64AnaRnPJ135FQSahvnozQQzIumhIo+yGNfSzZswFnBHGnyNyYrU c8ohBOUzcfxajy/y+HWa/0Tm3/y00NV+Xbod1BysWOZ69SM66HCkkwBJuTXLj/L51ihx SEWS3MVB5W9HhyUx5QC6QoykT3pZ27ro0bGqZKIIUPAC61vUgv3J/AcX4/nFD6OhmA7K fpRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234954; x=1719839754; 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=BZMgxVGycu8UCR6fk1Qn9uFvwvmJUGQDSX4skzfq58o=; b=CsVEdAJBtAb3etXR8wkVdguKGj2V3JryOQMmqlZPvPqQ130LVBfkhVNhq18v+w3ugn GhZxWDYIBJDcnTk2SVFCJfidMUOQRhA5sbbT28gixk3odWx5Oqke5DDk2NgJXT/CV+6r rOJ7DLfKPTuciYGO81d436Z+BnpNGIs/ZfUqtMxtG9iddl8oVCaI9vzsQIX5j2LwDy4r 6fwhyAkn9gSDFM9JQlJkasqJRvTIRDtSjp4qmvUWnBCmBH33XBl/DhEJetNFa2n3eihG ueZ0GOja3H7ZnrFO+AVDLgFiTbNVaAJZW5Taryd52V2bdtc0prvlINaA07JFbdDzWTDM AtaA== X-Gm-Message-State: AOJu0Yxex8eELlMooBNQ0nGvjGJFUzRNbrnY4GLzdc0lvFeNJ+PkLSVw hCjnHj0Lmky5UKe3XAxC/wbZyUueYQH9MQmb18UgBgaqEaphZErMIHq7E1xZUP3B74AYEiS3lhK R X-Google-Smtp-Source: AGHT+IG1wxI0mEsJtfyJYa1q2sytrtXFbHbPI1/6TvXJhzdV4v+DIDR/JQLSD4GwYQuo+UbmdCdhRA== X-Received: by 2002:a5d:58fa:0:b0:35f:1b73:1d83 with SMTP id ffacd0b85a97d-366e7a08ba5mr3921036f8f.4.1719234954103; Mon, 24 Jun 2024 06:15:54 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366bd575f6asm9398981f8f.6.2024.06.24.06.15.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:53 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 13/19] hw/sd/sdcard: Factor sd_req_get_rca() method out Date: Mon, 24 Jun 2024 15:14:34 +0200 Message-ID: <20240624131440.81111-14-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Extract sd_req_get_rca() so we can re-use it in various SDProto handlers. Return a 16-bit value since RCA is 16-bit. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-15-philmd@linaro.org> --- hw/sd/sd.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 04b141784b..b909a85d53 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -474,6 +474,14 @@ static void sd_set_rca(SDState *sd) sd->rca += 0x4567; } +static uint16_t sd_req_get_rca(SDState *s, SDRequest req) +{ + if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) { + return req.arg >> 16; + } + return 0; +} + FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) @@ -1097,7 +1105,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { - uint32_t rca = 0x0000; + uint16_t rca = sd_req_get_rca(sd, req); uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg; /* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1112,11 +1120,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Not interpreting this as an app command */ sd->card_status &= ~APP_CMD; - if (sd_cmd_type[req.cmd] == sd_ac - || sd_cmd_type[req.cmd] == sd_adtc) { - rca = req.arg >> 16; - } - /* CMD23 (set block count) must be immediately followed by CMD18 or CMD25 * if not, its effects are cancelled */ if (sd->multi_blk_cnt != 0 && !(req.cmd == 18 || req.cmd == 25)) { From patchwork Mon Jun 24 13:14:35 2024 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: 13709471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD94FC2D0D1 for ; Mon, 24 Jun 2024 13:17:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjYc-0004OG-RD; Mon, 24 Jun 2024 09:16:37 -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 1sLjYB-00041k-U7 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:08 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjY9-0005Yr-UK for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:03 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52cdf4bc083so2683836e87.2 for ; Mon, 24 Jun 2024 06:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234959; x=1719839759; 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=eqS+9elQ6EjTafFx/IwJ/1Wg3fHnvg3mIfJwf3uEmvY=; b=j6LrmzLp1nqmfhoMaLu63dcyl+6zSn0FVgkqczhcjradNyZjtfgYDXlFBmS16Xq7ln K5g+H/Cj6U5ubhnOqwMtFxsKfCdoUYAE6qUmhgNb0XSlLr7dcJTuSe4YIe+uH2qgKSe6 OfApWZgt0b7UOHIsZ7DbmaRBvSMDXjguxBXV2ROzlSajGkmgT3wQDczLVZIntbu/3fLh EW8KhBx/LslVM99t/zpDCqOdwfJ52uHHV8yRLFY43WPAZg8IeaymZiS5zag5yogvwYWX YdVNVvVDubysueZryklvPs/4THOfl1F3/04gO1vRwAPlq+IvnT8nR/g1PRLUjWfnXF9U bPAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234959; x=1719839759; 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=eqS+9elQ6EjTafFx/IwJ/1Wg3fHnvg3mIfJwf3uEmvY=; b=jSExQW3aehf609BUqMPzFyM2x1CNpV8NGhaOKOkIC7mrx+HeCrcjNNVjcLBznTDOYc Uw8nu9HoBoiryTRiv12Ra/u2OfouKc4lgA3y4Nzw8AZKhsFtNYi4RztMQfx9z7wZcTWo nWpN0Nc/7JD+BJAD7m0rbkzVoe7ySVfpwMvIzlUoD2pBo3JYbFHhmUh9jms7EZ0irLGS 13GoF2Zb5AnoFc85SA9qix6bE0wWqYD3io9VzpDR4BHAbhXFu7G/MvXj5i5hwK+OhJk1 i2+FJlVW6e77EHuhrwLAZhh/AMoOnzj06ZrJJ4x5kZ4LB4geanmosfyJ3omBnChu5QBB Vh+Q== X-Gm-Message-State: AOJu0Yw7qoe1hVqMxCZ7AaHxgrG9KtHAgCJOCvZbUWwRO3A/J+mLffJY 2hAbtVPjWzAwjgaegBxui36p6oZPJpLiuljYIZ81NwGL7GQDy0PKBHGUYpZ1muvSxBuGuGOY6// F X-Google-Smtp-Source: AGHT+IFyS54wSwLaWwP+A1nVE6XBR8GHOj8PUbJGl+3paXeYG7oVzZp8nmv92DfiyIdGzT+8VoUuUw== X-Received: by 2002:a05:6512:1050:b0:52c:e012:efad with SMTP id 2adb3069b0e04-52ce0610531mr4941757e87.12.1719234959448; Mon, 24 Jun 2024 06:15:59 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248191116fsm139386125e9.37.2024.06.24.06.15.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:15:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 14/19] hw/sd/sdcard: Only call sd_req_get_rca() where RCA is used Date: Mon, 24 Jun 2024 15:14:35 +0200 Message-ID: <20240624131440.81111-15-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12c; envelope-from=philmd@linaro.org; helo=mail-lf1-x12c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It will be useful later to assert only AC commands (Addressed point-to-point Commands, defined as the 'sd_ac' enum) extract the RCA value from the command argument. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-16-philmd@linaro.org> --- hw/sd/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b909a85d53..912b2f8984 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1105,7 +1105,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { - uint16_t rca = sd_req_get_rca(sd, req); + uint16_t rca; uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg; /* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1162,6 +1162,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 7: /* CMD7: SELECT/DESELECT_CARD */ + rca = sd_req_get_rca(sd, req); switch (sd->state) { case sd_standby_state: if (sd->rca != rca) @@ -1216,6 +1217,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_r7; case 9: /* CMD9: SEND_CSD */ + rca = sd_req_get_rca(sd, req); switch (sd->state) { case sd_standby_state: if (sd->rca != rca) @@ -1239,6 +1241,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 10: /* CMD10: SEND_CID */ + rca = sd_req_get_rca(sd, req); switch (sd->state) { case sd_standby_state: if (sd->rca != rca) @@ -1279,6 +1282,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 13: /* CMD13: SEND_STATUS */ + rca = sd_req_get_rca(sd, req); switch (sd->mode) { case sd_data_transfer_mode: if (!sd_is_spi(sd) && sd->rca != rca) { @@ -1293,6 +1297,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 15: /* CMD15: GO_INACTIVE_STATE */ + rca = sd_req_get_rca(sd, req); switch (sd->mode) { case sd_data_transfer_mode: if (sd->rca != rca) @@ -1525,6 +1530,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ + rca = sd_req_get_rca(sd, req); switch (sd->state) { case sd_ready_state: case sd_identification_state: From patchwork Mon Jun 24 13:14:36 2024 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: 13709466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D2E9C3064D for ; Mon, 24 Jun 2024 13:16:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjYg-0004Qw-TO; Mon, 24 Jun 2024 09:16:38 -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 1sLjYI-0004Fs-FJ for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:10 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYG-0005Zo-53 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:09 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42172ed3597so25439175e9.0 for ; Mon, 24 Jun 2024 06:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234965; x=1719839765; 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=o15lljW0J8mLU8KoPH/cOET32R/ivJ529Ef9M/rh/b8=; b=BfLxruUA5uyuhB7xUoaomyYBhg1tNFjGtXTgn9K38tSe9K/6civ/LiBRgUTC1+YS+p SVL8WNo3OlyX2z2pin8YdzrDpH6+IfMQawSZpeRZNm404k7GIcG3hb7wXHY9A06OTEWW +IN2fG53ZR+hwLU+WbRYq2cCLwfSF03uwziUIQNbRSfeS7OkYOoDpV6F6LUrB7HIHVct P1por0bpwHIorpSqgZorWLyTGm+dBUl0prrDYMdxKYNVg+rbvygoicz3QpYJpttzz+Ql PwRVQr6Zy+pjS3WumIUYV2S/zaq+blRHRwrmfl3X93lfm6vVnMxvRLjfVA+WK0Yoozp6 GNlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234965; x=1719839765; 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=o15lljW0J8mLU8KoPH/cOET32R/ivJ529Ef9M/rh/b8=; b=rqFtB6Qz43CPg81B4Od51Q/rz0rPccU8ZHzP2Dfop/Qk9NGGrD8LcPhTKxfuUqRmpi 9D3g2RywEj84EubqaCOWffrvWbuezpQ/YN1dejthkaxUk2OCXFopuQR86AnAZwPc0QVi 362fOy6fU6AIJSr8Cg/M6zBMKN2csn8qpYdGS3AzB9KKr9h4YTkl1Yn9LvHJ8rDAD6hy AJwFdgwvwJt8wPRcnQt7P5VwQCStvbmcLMAotizV6P2XblLWiCO3WiGvv0OWAqdy9LaK MLAE90c1vGF5Xdw82408rOCs4xrOfuMs2EhNOd5pRgYngBWFHQux0/tj+EnVj3fw7Z6M tLNg== X-Gm-Message-State: AOJu0YxVVybwXfUB24RFItgh4Qzn28ooEwHIAogj9jI6Y9+FcqZ/PM+u qQIHMfmiXrN8ssjXRkwllha501PTgvNs5ibCpjSFeWBnyP696yp5p75b3xSIwe2z1t0Wv/5MtxL G X-Google-Smtp-Source: AGHT+IGSCkTeNsKh7FoLWWpmHwlKURccYcY5MFn5ioNd47UTcfbI82HgT/ynqnx2SmthgSnDr85/zg== X-Received: by 2002:a05:600c:3b28:b0:421:347a:f0a6 with SMTP id 5b1f17b1804b1-424893dfbadmr44229715e9.3.1719234964807; Mon, 24 Jun 2024 06:16:04 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248179d506sm132267055e9.6.2024.06.24.06.16.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 15/19] hw/sd/sdcard: Factor sd_req_get_address() method out Date: Mon, 24 Jun 2024 15:14:36 +0200 Message-ID: <20240624131440.81111-16-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Extract sd_cmd_get_address() so we can re-use it in various SDProto handlers. Use CARD_CAPACITY and HWBLOCK_SHIFT definitions instead of magic values. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-17-philmd@linaro.org> --- hw/sd/sd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 912b2f8984..51ab7cd003 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -582,6 +582,14 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response) stl_be_p(response, sd->vhs); } +static uint64_t sd_req_get_address(SDState *sd, SDRequest req) +{ + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { + return (uint64_t) req.arg << HWBLOCK_SHIFT; + } + return req.arg; +} + static inline uint64_t sd_addr_to_wpnum(uint64_t addr) { return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); @@ -1106,7 +1114,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; - uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg; + uint64_t addr = sd_req_get_address(sd, req); /* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. From patchwork Mon Jun 24 13:14:37 2024 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: 13709478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4650CC2D0D1 for ; Mon, 24 Jun 2024 13:18:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjYq-0004rp-Gh; Mon, 24 Jun 2024 09:16:45 -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 1sLjYL-0004OP-UF for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:14 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYK-0005ap-3R for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:13 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-362f62ae4c5so2491215f8f.1 for ; Mon, 24 Jun 2024 06:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234970; x=1719839770; 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=WHRr6B3uuTd3EFTNdg9fHFN+Zyvmx7WRQ/X+xj1mCi4=; b=gqBOqknQ/OIPJxDm3WWkgHhOi6csfteVs4louhsZw6C/BYDtx3Bzunaz3alzCoPYQv mIusBWY9bhlP6I4fNerJjoGcXk4tuq8hJtW1V9JIYlOk+LcSWE92R5OT4vsiB7DPTysa eKGdcgqVrfzQ+r+lIiX+QpQQNlGezTev4bTdasjPy45VM569XSiujIOgUi5t28o9U3sT T2yWw1jcgSON8Xf3o8p03G3JPPN89aRH93EeMDKInZilOTsbSuWL7O3uAn1TZPtgzATI n4R9d+zY0axZM+bdO0FGfQramUzzMk4Ades6n9pFzyyxlJgwNtZjKgd+fIsbUlTV3KTE 4TLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234970; x=1719839770; 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=WHRr6B3uuTd3EFTNdg9fHFN+Zyvmx7WRQ/X+xj1mCi4=; b=KG40Mj5ni/CYOG057/iMD3t+ZbpmfyCF+bizrGJRGH50dT7K5bE8ei6dXVAKh4NqZV vo/Et3iUNzsvgw6u9hXjhMJZP3pFzs7uV9TP3Ym0c+d87KKCm2YO3WzI9hPw98fCBPH2 lYzkdMEttewIejtxm3T7cfuJPY63TuXcmOWg71NPjjyP03m/RY7BhAiaPOJMjDi+n+jA uYbkSg31paGX6hhSqbRwOd1olKUES5AMbpy5NybBNY+7CC8i709z7E2r4uGH8MpY1gxi VIetKKJIlIb4I8T0J1+jYgCIqr+aaoJq02yH0lvCqNEgS5pHB4fE7uQQDA92mIQFawkP vAKg== X-Gm-Message-State: AOJu0YwR5j7J/RyccM1DBQlSY3yPu9k3p4uGMRx51fJiuvVMMai7HV5E 9f129PpipTR6EE/vNIN5h/19wByAdXAqZoKgXscOnxeRXcl1jAQLlZUHJk2MDHBtRMKgZicyxM9 x X-Google-Smtp-Source: AGHT+IERn+fMNW0WYrw6V3UBcWIEEfdj89cCClvSkzcNO7C7hAJJgrLWZeluXp4cEF2HafnF+Mr/lg== X-Received: by 2002:a5d:690e:0:b0:365:aec0:e191 with SMTP id ffacd0b85a97d-366e32956e7mr4379778f8f.21.1719234970345; Mon, 24 Jun 2024 06:16:10 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366383f6da6sm10006561f8f.12.2024.06.24.06.16.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 16/19] hw/sd/sdcard: Only call sd_req_get_address() where address is used Date: Mon, 24 Jun 2024 15:14:37 +0200 Message-ID: <20240624131440.81111-17-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=philmd@linaro.org; helo=mail-wr1-x42e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It will be useful later to assert only ADTC commands (Addressed point-to-point Data Transfer Commands, defined as the 'sd_adtc' enum) extract the address value from the command argument. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-18-philmd@linaro.org> --- hw/sd/sd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 51ab7cd003..3e4eb656e1 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1114,7 +1114,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; - uint64_t addr = sd_req_get_address(sd, req); + uint64_t addr; /* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. @@ -1239,7 +1239,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_sendingdata_state; memcpy(sd->data, sd->csd, 16); - sd->data_start = addr; + sd->data_start = sd_req_get_address(sd, req); sd->data_offset = 0; return sd_r1; @@ -1263,7 +1263,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_sendingdata_state; memcpy(sd->data, sd->cid, 16); - sd->data_start = addr; + sd->data_start = sd_req_get_address(sd, req); sd->data_offset = 0; return sd_r1; @@ -1339,6 +1339,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 17: /* CMD17: READ_SINGLE_BLOCK */ case 18: /* CMD18: READ_MULTIPLE_BLOCK */ + addr = sd_req_get_address(sd, req); switch (sd->state) { case sd_transfer_state: @@ -1359,6 +1360,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Block write commands (Class 4) */ case 24: /* CMD24: WRITE_SINGLE_BLOCK */ case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ + addr = sd_req_get_address(sd, req); switch (sd->state) { case sd_transfer_state: @@ -1417,7 +1419,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (sd->size > SDSC_MAX_CAPACITY) { return sd_illegal; } - + addr = sd_req_get_address(sd, req); switch (sd->state) { case sd_transfer_state: if (!address_in_range(sd, "SET_WRITE_PROT", addr, 1)) { @@ -1439,7 +1441,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (sd->size > SDSC_MAX_CAPACITY) { return sd_illegal; } - + addr = sd_req_get_address(sd, req); switch (sd->state) { case sd_transfer_state: if (!address_in_range(sd, "CLR_WRITE_PROT", addr, 1)) { @@ -1461,7 +1463,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (sd->size > SDSC_MAX_CAPACITY) { return sd_illegal; } - + addr = sd_req_get_address(sd, req); switch (sd->state) { case sd_transfer_state: if (!address_in_range(sd, "SEND_WRITE_PROT", From patchwork Mon Jun 24 13:14:38 2024 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: 13709477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 729FFC2BD09 for ; Mon, 24 Jun 2024 13:18:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjZ9-0005LR-JA; Mon, 24 Jun 2024 09:17:06 -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 1sLjYU-0004Vq-Er for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:31 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYS-0005c3-6z for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:21 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ec4eefbaf1so32206141fa.1 for ; Mon, 24 Jun 2024 06:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234976; x=1719839776; 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=+OyvAZYAFCHsIdySGDiXeFQ2F3N56N52JzU6FXve/Tk=; b=DzUU0xiczFjZbc9WgaPziF66c2woNd8KtcRbC03A9JHkQHZVSEH+VU0YH5omWSgRWr njhyl6h0yZVWdsPwP4ZxRuY9De3ltdIqWaMGPsGSZcYxse9V360AL03A2gLhCoJ/4A09 lfU+K5bVJK9OjM5B2DL0baVC3FMDFS4yjGL9n0A/YSF2KCq9uX96AW4RKp3KJUenwziV Qm6bVyIx6pVL6uUkbfBb2h2y55nl3DoIWylVOiTXrxAClRZsECQK5Yju6Uk9X3EVtnPn oeT4BUtXnZr1C6MRJjnK2YVyM1RzNEMT50ZOjpgrY+ylOhxZ61Pc5bb6LCm4qe34Q3ox RqZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234976; x=1719839776; 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=+OyvAZYAFCHsIdySGDiXeFQ2F3N56N52JzU6FXve/Tk=; b=WX3M8uRmzf010mGhec5x4D/oAIcu0P5VUMOPvJWUTqq+Cl9D+h9UzUhLpY2DDyIpKP w4S8won5JL+mo1qqUNLgq3NalbIgZ2HOSiqR6VAWn2jfc11Yq3P5UWeKCveEatY09CLj uGEeErGmdig23tg0014+x5v3MHQCnZGLTIwnsFWLdVWQcEhZ6OZJgC55B1Aj4gJj9xxa ochFoifHflbhcg4dN/jkiN+AdE6NQokj390CLzPD6CMdgSE54AP54JxtuCtJsuPLZwc7 3bAw8ajo8lF1EPBdpGsTnA7I1jFyKR0bCN2uVxnNA+gEH+SPjgQBLcc/TSrF92edHhYY BDaQ== X-Gm-Message-State: AOJu0Ywf3z7qKiBjq3YyjNw+iL0TUrFUC0K4QPEHBQXwl6XcNlmKzNJg aftoApYQJozIZWbybwkt5nVvkpTffAArEclCVfYlzuLKLS53zCp2+zrjULczPUwziEzfT7McTI3 u X-Google-Smtp-Source: AGHT+IFxIv8Hp01Og8kxt3lqIdEFZkOEKyHPfxi9T/bYxKs3Qjy8/GnA5UNvZIgZr6aKDO4zDCOcgw== X-Received: by 2002:a2e:b788:0:b0:2ec:4487:6a8f with SMTP id 38308e7fff4ca-2ec5b3d4ab1mr26520821fa.37.1719234975804; Mon, 24 Jun 2024 06:16:15 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366388c41b0sm10007103f8f.44.2024.06.24.06.16.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 17/19] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch Date: Mon, 24 Jun 2024 15:14:38 +0200 Message-ID: <20240624131440.81111-18-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=philmd@linaro.org; helo=mail-lj1-x232.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Having the mode switch displayed help to track incomplete command implementations. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-19-philmd@linaro.org> --- hw/sd/sd.c | 75 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3e4eb656e1..969340e5cb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -178,6 +178,17 @@ static const char *sd_version_str(enum SDPhySpecificationVersion version) return sdphy_version[version]; } +static const char *sd_mode_name(enum SDCardModes mode) +{ + static const char *mode_name[] = { + [sd_inactive] = "inactive", + [sd_card_identification_mode] = "identification", + [sd_data_transfer_mode] = "transfer", + }; + assert(mode < ARRAY_SIZE(mode_name)); + return mode_name[mode]; +} + static const char *sd_state_name(enum SDCardStates state) { static const char *state_name[] = { @@ -1018,6 +1029,15 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) return sd_illegal; } +static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong mode: %s (spec %s)\n", + sd_proto(sd)->name, req.cmd, sd_mode_name(sd->mode), + sd_version_str(sd->spec_version)); + + return sd_illegal; +} + static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Unknown CMD%i for spec %s\n", @@ -1156,18 +1176,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 6: /* CMD6: SWITCH_FUNCTION */ - switch (sd->mode) { - case sd_data_transfer_mode: - sd_function_switch(sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + sd_function_switch(sd, req.arg); + sd->state = sd_sendingdata_state; + sd->data_start = 0; + sd->data_offset = 0; + return sd_r1; case 7: /* CMD7: SELECT/DESELECT_CARD */ rca = sd_req_get_rca(sd, req); @@ -1291,33 +1307,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 13: /* CMD13: SEND_STATUS */ rca = sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (!sd_is_spi(sd) && sd->rca != rca) { - return sd_r0; - } - - return sd_r1; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + if (!sd_is_spi(sd) && sd->rca != rca) { + return sd_r0; + } + + return sd_r1; case 15: /* CMD15: GO_INACTIVE_STATE */ - rca = sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (sd->rca != rca) - return sd_r0; - - sd->state = sd_inactive_state; - return sd_r0; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + rca = sd_req_get_rca(sd, req); + if (sd->rca == rca) { + sd->state = sd_inactive_state; + } + return sd_r0; /* Block read commands (Class 2) */ case 16: /* CMD16: SET_BLOCKLEN */ From patchwork Mon Jun 24 13:14:39 2024 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: 13709481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59612C2D0D1 for ; Mon, 24 Jun 2024 13:19:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjYt-0005ES-6V; Mon, 24 Jun 2024 09:16:48 -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 1sLjYY-0004Wb-Jc for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:31 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYW-0005cc-Uf for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:26 -0400 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2ec52fbb50cso21891711fa.2 for ; Mon, 24 Jun 2024 06:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234981; x=1719839781; 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=cdaAnkUJwowtFskE1jnezvCSjmf7OfsaigbewXS0J/c=; b=dcxT2kCIg8m9Hm+Ga5mbs6X3mJ943gViHmm2gNoloOKAZtNngKXMetmVLFB3NO7Lpx S4bhDs7GDnMmrf1zgpSlm2Vc+AmGsR+FYhNofP2xe2e3xf+Mm0DHhj1evcVKzqA9l2Bo IRzcHAIXqG9H8K1kSDJvVLSw7CrCBHuLIjLsf03by7zQ3hMxIWG3wr5M54/WV2syG3Kq iykVAuVgRFBf4jDPUIEkhHHmw1M+MR2l6H8ewkW/kcXIBIsAtqCl3pIvt/xQrppTiuLT 6XVxBt2GpzBL9reAWXyZl7dHDH19cZoGg60eP0xfn1mEwPwEZcRkEIgPQzs+UGI5gHJq k9tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234981; x=1719839781; 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=cdaAnkUJwowtFskE1jnezvCSjmf7OfsaigbewXS0J/c=; b=lLoUwfYIRXhdmdpLIgH9XIx2XWPAm/L4Wu+jJ4CVFmcFWVJi4g2IjNtoZPwVeqYXzi bTWOehH0vNQmGibbXcVnFmqBi0Y+se5M8QUO0HrwBK9z6VeMIjx5KO4yW2DxrrnDY6hr j7E3kYwwK6uf6mLuIsQNy8jy2PRAy1YfafOoZdJ4LmtOtalqjhniqvMeFWXkiAAHwjAg V1wOT9DzUJi3tfeeLMLfuaa3M7gCCRa52dhHvPDyjYgLukUBRwqHg+6WCa7WukhTVQEh EuS0dRgSQOMCMC3bNSddtOtIb7EHqkyyl9GlI1YZoq9QgO2tCTJyJbqMyU98DcJf/AFd 5ENA== X-Gm-Message-State: AOJu0YwK1EYW81hqreT21eT+mWlHIVfR0AP5gura0pB5rS09eIaJGG6M +dLnIDCntTm55AROdUD75nUYbsWJkTIJWAyA1hE7pzz7viFgRbMOgqXJ0rfSIe4dUi8wumOcLvs 1 X-Google-Smtp-Source: AGHT+IGDCutJFfSVzkWUgg0W44sDuHKsWlIUnWlRCPJImUKzZ3tvf297RsnPU4U220VXVY02+jN/2g== X-Received: by 2002:a2e:890d:0:b0:2eb:e258:717f with SMTP id 38308e7fff4ca-2ec5b2f0400mr27285961fa.42.1719234981135; Mon, 24 Jun 2024 06:16:21 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208e13sm171560425e9.36.2024.06.24.06.16.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 18/19] hw/sd/sdcard: Inline BLK_READ_BLOCK / BLK_WRITE_BLOCK macros Date: Mon, 24 Jun 2024 15:14:39 +0200 Message-ID: <20240624131440.81111-19-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::236; envelope-from=philmd@linaro.org; helo=mail-lj1-x236.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These macros only save 3 chars and make the code harder to maintain, simply remove them. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-20-philmd@linaro.org> --- hw/sd/sd.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 969340e5cb..d4e3d079a8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -819,8 +819,6 @@ static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) } } -#define BLK_READ_BLOCK(a, len) sd_blk_read(sd, a, len) -#define BLK_WRITE_BLOCK(a, len) sd_blk_write(sd, a, len) #define APP_READ_BLOCK(a, len) memset(sd->data, 0xec, len) #define APP_WRITE_BLOCK(a, len) @@ -872,7 +870,7 @@ static void sd_erase(SDState *sd) continue; } } - BLK_WRITE_BLOCK(erase_addr, erase_len); + sd_blk_write(sd, erase_addr, erase_len); } } @@ -1903,7 +1901,7 @@ void sd_write_byte(SDState *sd, uint8_t value) if (sd->data_offset >= sd->blk_len) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; - BLK_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd_blk_write(sd, sd->data_start, sd->data_offset); sd->blk_written ++; sd->csd[14] |= 0x40; /* Bzzzzzzztt .... Operation complete. */ @@ -1929,7 +1927,7 @@ void sd_write_byte(SDState *sd, uint8_t value) if (sd->data_offset >= sd->blk_len) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; - BLK_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd_blk_write(sd, sd->data_start, sd->data_offset); sd->blk_written++; sd->data_start += sd->blk_len; sd->data_offset = 0; @@ -2077,8 +2075,9 @@ uint8_t sd_read_byte(SDState *sd) break; case 17: /* CMD17: READ_SINGLE_BLOCK */ - if (sd->data_offset == 0) - BLK_READ_BLOCK(sd->data_start, io_len); + if (sd->data_offset == 0) { + sd_blk_read(sd, sd->data_start, io_len); + } ret = sd->data[sd->data_offset ++]; if (sd->data_offset >= io_len) @@ -2091,7 +2090,7 @@ uint8_t sd_read_byte(SDState *sd) sd->data_start, io_len)) { return 0x00; } - BLK_READ_BLOCK(sd->data_start, io_len); + sd_blk_read(sd, sd->data_start, io_len); } ret = sd->data[sd->data_offset ++]; From patchwork Mon Jun 24 13:14:40 2024 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: 13709472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D40ECC2D0D1 for ; Mon, 24 Jun 2024 13:17:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLjZM-0005jU-Sg; Mon, 24 Jun 2024 09:17:18 -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 1sLjYe-0004ix-1N for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:37 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYb-0005de-N1 for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:31 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ec1620a956so51699961fa.1 for ; Mon, 24 Jun 2024 06:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234987; x=1719839787; 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=HXfJJfCbngNXWETKRmSoaVmSjOkjTU89WVvhepuXul8=; b=fir262VdbE3+A4+6tFWLLdW2ydwg8ioyytaFvNDzRA70DQdUKTvy3z72csUw7XXVJO kb7D3mlckeu13XzwJpgr9GRbLz/gXQgB+6K/mzr+CwlTOOy9DqklWhdiBtCDrLfyDYsw BcpSMR4RbA6IHhXalUpQZe2+3rIzb/VfjsFkRSjWWWSQMN0mcT7b8GbsU4+6PnfTJKAC +8L8a/3oM0xqbgTIf6B/S+mr3x9wDGTJEsvf8k+8fYM777dIFHeeU0XV00DUpHU7XHZj /6E7ltMTVMums8hvQUi2kLWQHkUqC7E47WS9H+I8ZrNs8DCVTHuq3pVlltTtw9AnyAbl Luhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234987; x=1719839787; 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=HXfJJfCbngNXWETKRmSoaVmSjOkjTU89WVvhepuXul8=; b=A+eE1xzVHhO0Q7MQzJrCmClnZ7VPw1hYq5WOssxMkZf5Jh8Bp5eROkUr1WoTLuODha i/jayxtNw78dl+tnqjZKOW1aaCMPUbbXpmJCEg2XEc1RTKk+fHxVlAce5UlTQOtxoFeh BEqK1oh3Qx2MxgcwlZw9lbVJk6n8GtjVYScMLjf72KEJQXLvaP6DXdltGcaZiLBig/vT IPX1aYqjUMxoxLKFwv9/w2kgZH/5SSH1tVTGuG88q43RFhDYatdZfJp3B7m8NtgKgDPh +sktbRQs8OIydkakqFTHO/lpcMCAjyGObGURundGpVO23QMP+Y3Z22bPvrbgW5yR0iw4 +CFw== X-Gm-Message-State: AOJu0Yw23i5Hl1AK+uaUSnuhuBfuJRBYPgNf3mLkjtKHAlBIHmAqr7PO Y2ioJJo2Awy4+WSYQV9omfKkvJk3v+R0ag9L1iPBCEmIWsNM478TLaymUDmHT2TsDappuCRRDyY Y X-Google-Smtp-Source: AGHT+IF/r9Rw0Zf+hKADiv4wQF9oQoRWpOXvNQqoFGXoA9GvckLHqQzcd5DQsMR8irUEKhB4624axQ== X-Received: by 2002:a05:651c:211d:b0:2ec:5dfc:a64e with SMTP id 38308e7fff4ca-2ec5dfca6demr30542061fa.0.1719234986576; Mon, 24 Jun 2024 06:16:26 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248482f1c4sm120290265e9.10.2024.06.24.06.16.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 19/19] hw/sd/sdcard: Add comments around registers and commands Date: Mon, 24 Jun 2024 15:14:40 +0200 Message-ID: <20240624131440.81111-20-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=philmd@linaro.org; helo=mail-lj1-x22c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-21-philmd@linaro.org> --- hw/sd/sd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d4e3d079a8..a48010cfc1 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -315,6 +315,8 @@ static uint8_t sd_crc7(const void *message, size_t width) return shift_reg; } +/* Operation Conditions register */ + #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24) @@ -364,6 +366,8 @@ static void sd_set_ocr(SDState *sd) } } +/* SD Configuration register */ + static void sd_set_scr(SDState *sd) { sd->scr[0] = 0 << 4; /* SCR structure version 1.0 */ @@ -386,6 +390,8 @@ static void sd_set_scr(SDState *sd) sd->scr[7] = 0x00; } +/* Card IDentification register */ + #define MID 0xaa #define OID "XY" #define PNM "QEMU!" @@ -411,6 +417,8 @@ static void sd_set_cid(SDState *sd) sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1; } +/* Card-Specific Data register */ + #define HWBLOCK_SHIFT 9 /* 512 bytes */ #define SECTOR_SHIFT 5 /* 16 kilobytes */ #define WPGROUP_SHIFT 7 /* 2 megs */ @@ -480,6 +488,8 @@ static void sd_set_csd(SDState *sd, uint64_t size) sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; } +/* Relative Card Address register */ + static void sd_set_rca(SDState *sd) { sd->rca += 0x4567; @@ -493,6 +503,8 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req) return 0; } +/* Card Status register */ + FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) @@ -623,6 +635,8 @@ static void sd_reset(DeviceState *dev) sect = sd_addr_to_wpnum(size) + 1; sd->state = sd_idle_state; + + /* card registers */ sd->rca = 0x0000; sd->size = size; sd_set_ocr(sd); @@ -1055,6 +1069,7 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { if (sd->state != sd_inactive_state) { @@ -1065,6 +1080,7 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) return sd_is_spi(sd) ? sd_r1 : sd_r0; } +/* CMD1 */ static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req) { sd->state = sd_transfer_state; @@ -1072,6 +1088,7 @@ static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req) return sd_r1; } +/* CMD2 */ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) { switch (sd->state) { @@ -1083,6 +1100,7 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) } } +/* CMD3 */ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) { switch (sd->state) { @@ -1097,6 +1115,7 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { @@ -1113,6 +1132,7 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) return sd_r1; } +/* CMD23 */ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) { if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {