From patchwork Mon May 30 19:37:52 2022 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: 12864898 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 3E391C433EF for ; Mon, 30 May 2022 19:41:08 +0000 (UTC) Received: from localhost ([::1]:54420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlGF-0000DK-7I for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:41:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlDn-0006DZ-PF; Mon, 30 May 2022 15:38:35 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:36681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlDm-0008B7-3M; Mon, 30 May 2022 15:38:35 -0400 Received: by mail-pl1-x632.google.com with SMTP id u18so4884629plb.3; Mon, 30 May 2022 12:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ng4oM9dmzGsSv+SiHIZH/9jskdqZ20IbrVwJee5u3hE=; b=i4Sy6dLAQI6aDznPasY9YnLJkbl55bbrA2XJTEENcROf0ibcJ58sGxGEqrI7G3x/vw 20sjxBSzkSo9anAqr0Bp6DK6F3g3UCP8BLmUSQebaUi0piJrAGv2FMWTHtrRWwRY9ZKb q8VqmxkWuj+B6j1W7OEN88UBGFCC9/FlRazGNvK+FKBvXPqskBm6fn3BvHBljxSA/Et3 siBzV6RH4jAHZDZ6/nE7eugHg9w0TL1ZeSdhcLYydR/WYf7H02UItgJlBMQY3r6P4KPW IMTLZ3rUT5smMSnDWYQBwdJ1PxmG7yAqdcKXF67z3Ao0Xb5nw43LTeViz6knoAMAQBCt o9yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ng4oM9dmzGsSv+SiHIZH/9jskdqZ20IbrVwJee5u3hE=; b=KX9vhWgdRtB2S4sSIlew0M8baQH9f3JegFNtncHrrNNbcgZuklNimvMloDurHYVccf NRPdSbkuEDSf0VE35wwVxuN9cKdGti9a2J5fOWQ1PHyyYePs3O5ElQ1qErtSohOCmZ+c Rfl+kZK5cS8D9t5rtz5Xit/uN8a67dl1oqsQO4t/HJcr0hvw0xcYxgWTtnvJj1GkH4ZH 18r9nbHSXreFED8odTZeAWkFEr1lOTIDXbevn6nqQvwW3w7z4OZQ1VYd7/4EqbsLQvTO /sz40LB9ycklNmmwOei8Qs5gjUoLp21XEE6MAFl/gOHr1YX/a854Fdm90eLZKyWkObrJ mV7A== X-Gm-Message-State: AOAM533hh8snU2ibQl/WwtCpm+0w5yZYzLyRdi9Wn88D7Os4VYMl4k5t WOCgOvf9DPewU5ol0g7IcX4InMl6n+A= X-Google-Smtp-Source: ABdhPJx+OD7mx3wGzrM+kw+WMo+m39tN51RKYOvKBzNCjeOCTfKoryIoRiq9Qh92OhxOe0XvVV3ZcQ== X-Received: by 2002:a17:903:1212:b0:15e:7d94:e21d with SMTP id l18-20020a170903121200b0015e7d94e21dmr57352558plh.92.1653939511992; Mon, 30 May 2022 12:38:31 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id gk13-20020a17090b118d00b001e28e80a8d6sm66530pjb.38.2022.05.30.12.38.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:38:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 01/25] hw/sd/sdcard: Return ILLEGAL for CMD19/CMD23 prior SD spec v3.01 Date: Mon, 30 May 2022 21:37:52 +0200 Message-Id: <20220530193816.45841-2-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé CMD19 (SEND_TUNING_BLOCK) and CMD23 (SET_BLOCK_COUNT) were added in the Physical Layer Simplified Specification v3.01. When earlier spec version is requested, we should return ILLEGAL. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20220509141320.98374-1-philippe.mathieu.daude@gmail.com> --- 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 8e6fa09151..7e3bb12b1a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1263,7 +1263,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - break; + goto bad_cmd; } if (sd->state == sd_transfer_state) { sd->state = sd_sendingdata_state; @@ -1274,7 +1274,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 23: /* CMD23: SET_BLOCK_COUNT */ if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - break; + goto bad_cmd; } switch (sd->state) { case sd_transfer_state: From patchwork Mon May 30 19:37:53 2022 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: 12864901 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 9FC95C433F5 for ; Mon, 30 May 2022 19:43:52 +0000 (UTC) Received: from localhost ([::1]:33746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlIt-0005kH-KS for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlDx-0006Un-3N; Mon, 30 May 2022 15:38:45 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:41787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlDv-0008CN-JF; Mon, 30 May 2022 15:38:44 -0400 Received: by mail-pg1-x530.google.com with SMTP id e66so10876351pgc.8; Mon, 30 May 2022 12:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bJO2kVCczmXNji68pRuyrx67SZ6xs6b+pC/1wsj0JMU=; b=Mw0WMZI/hpylm9nOZIm9BtHTXHLXQ3Ckj7kMDOLKLaNTGP4rJg7dvpcxohvgbN6DuY bakrmetn2e/k1rYQKmXwcDMdPOL5L0YkU/Ya+cnJhpO9DRyYSqN9uvD4Ae8NabAe8GHU pMwhlh/UPv1yr33/SoFdoKlfxwWGtYgdPBKiBaw4kxL6wLew1vaU/DfAcQCtmGOFxr6u 5MSp3jjI4Bkb8nYgbfSa6602LaTGB9bbhsMBruEZWTfk/dYhnPF99deCxRnNp7F/cYWt lTXwLROPRO7uIGl21YwVoOpGSl9SsSs4ScIQ41ybAtEVoxx1YkYrGVotcmD/mM1BgGT5 FGnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bJO2kVCczmXNji68pRuyrx67SZ6xs6b+pC/1wsj0JMU=; b=sg11wwq1iqQHZIe+GAHW6Rbmcrl2nawgRkTNhxQFVONToj+hMEcn0+3BIeaaHzmoY1 EXDmxS6/MsvFZthr4xYXrSdQded4jQymIHSxMMpDgAeqvhgqAYHtpmZ2dXLsiVwMX18Z 52lu+uWgRoHTXrWbiUehNXpBdi/Hry/RvMs1q3eWFzKLQJL0oen1oUKsHJpuiCFP5jxw VMjE+bHrAGWIIeu1nZXFj/zrTVi/joNQrUfDaPHBvHcTwVWviLqzLkzhjQ/KeRRb/6Ou MdJc2xVbKwqclVkupDe6hreyYl3QXwr4VUVKHFD3HjvZwd239VsyHufLzfCm9BwQy8tN xzcA== X-Gm-Message-State: AOAM5328LuhwTGcnaucoWmhR+XExcVyBcAT/uAGtiVIue6lLG51GIWDt WNXSDlp5zd8MGO1QJE8zn6cqoN3uoLc= X-Google-Smtp-Source: ABdhPJz32BLkdJl/6evjL9tbbPcjZrBvpRbm9mKaLvTqeu04Dzb0b8KAVF+MOEGC/OiUhYQQCtR2dg== X-Received: by 2002:a05:6a00:889:b0:510:91e6:6463 with SMTP id q9-20020a056a00088900b0051091e66463mr58666738pfj.58.1653939520514; Mon, 30 May 2022 12:38:40 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id ij30-20020a170902ab5e00b00163cdf1a200sm3514900plb.38.2022.05.30.12.38.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:38:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 02/25] hw/sd: When card is in wrong state, log which state it is Date: Mon, 30 May 2022 21:37:53 +0200 Message-Id: <20220530193816.45841-3-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé We report the card is in an inconsistent state, but don't precise in which state it is. Add this information, as it is useful when debugging problems. Since we will reuse this code, extract as sd_invalid_state_for_cmd() helper. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-2-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7e3bb12b1a..b0e7a7e6d0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -966,6 +966,14 @@ static bool address_in_range(SDState *sd, const char *desc, return true; } +static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s\n", + req.cmd, sd_state_name(sd->state)); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1534,9 +1542,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_illegal; } - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s\n", - req.cmd, sd_state_name(sd->state)); - return sd_illegal; + return sd_invalid_state_for_cmd(sd, req); } static sd_rsp_type_t sd_app_command(SDState *sd, From patchwork Mon May 30 19:37:54 2022 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: 12864899 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 DCA75C433F5 for ; Mon, 30 May 2022 19:41:27 +0000 (UTC) Received: from localhost ([::1]:55680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlGY-0001G0-VG for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:41:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlE5-0006o6-FE; Mon, 30 May 2022 15:38:53 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:44589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlE4-0008D6-0f; Mon, 30 May 2022 15:38:53 -0400 Received: by mail-pf1-x431.google.com with SMTP id g205so172891pfb.11; Mon, 30 May 2022 12:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tzxi57a4Nyv9nQAXUie7IHq8uaYskXtrhIjYfuzd22k=; b=M8yLfIuJ3ksZ/wr+M/5k4Xb0oCnurH1kaDaJ2LuLJ47ntv2uG6mDcDPpvds4YMFQUm INcu1c5rmFlWVHDqUjPVhe1u1EBsrQRBYYUdtlFREtvYESelBhT3pw6Eq1dgdKCaDo++ naPdM5yyPUAP2W86kbBA27dFp+oHDn+y/MA2eIte03gpu6RxxJWzAIwYwsh+ugNaDkZu pFJRkuGj2uFI5MkiC5dvXkfBP3R4UkyDVDUi8hHyg5V9GBNFc7eF/68IcOXJJnh1aB7j 3EZzu+abmB5STE6ENrMi1f8EbpUjwTvImpI7r6MnG9HVwmp09+edx1vw/aBZuBvlAW/o DQhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tzxi57a4Nyv9nQAXUie7IHq8uaYskXtrhIjYfuzd22k=; b=jjaiBPzxYHdKvpWsLc8HgVQlft7CkMZRJ0UYXnmi0mqyyKs3q1iF9cTby9CLl1rSWV ComkWzCQha/trJtg/A7nhWoIVv+kofXLP9Cy++2Mpbr057C9Sg0EN8bGTHZS+J4bEozU 4oXimsGQoCP9p0ByUjpnPxaAHWmvjKVxm/YJyeMdVhNszevn2K0NfHpwwruJVgPi67FT pnUTonDCXYKmAgd3cIyh7rG2bNYbukEguBV+hrqG8J2DSGKkGfG2/07cTTXf6oTvlIJk zx2fj5PG0n6rswcsNs92T63k8cK5Pm75if2ABE3Vb5A1IeJ+B7bwIaRbvezybaLh3JEC T7zQ== X-Gm-Message-State: AOAM532mpslumo2TvQbXa4vyBQoowT6OERB05I6ws1YHLpq3mdNQ0zQk dBF2253WxXjzW5y5TZ3lPaIeEf4nFok= X-Google-Smtp-Source: ABdhPJx35Vqyd0g0GUNppHz38SHtmi66jAjv+t2d71+q/aU3WMhnmNowjlTgtLXLoerMDc35607Ckg== X-Received: by 2002:a05:6a00:1690:b0:517:cc9e:3e2d with SMTP id k16-20020a056a00169000b00517cc9e3e2dmr58202395pfc.0.1653939529254; Mon, 30 May 2022 12:38:49 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v189-20020a6389c6000000b003c14af50607sm9011233pgd.31.2022.05.30.12.38.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:38:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 03/25] hw/sd: When card is in wrong state, log which spec version is used Date: Mon, 30 May 2022 21:37:54 +0200 Message-Id: <20220530193816.45841-4-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pf1-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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Add the sd_version_str() helper. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b0e7a7e6d0..b3e61b9f84 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -145,6 +145,19 @@ struct SDState { static void sd_realize(DeviceState *dev, Error **errp); +static const char *sd_version_str(enum SDPhySpecificationVersion version) +{ + static const char *sdphy_version[] = { + [SD_PHY_SPECv1_10_VERS] = "v1.10", + [SD_PHY_SPECv2_00_VERS] = "v2.00", + [SD_PHY_SPECv3_01_VERS] = "v3.01", + }; + if (version >= ARRAY_SIZE(sdphy_version)) { + return "unsupported version"; + } + return sdphy_version[version]; +} + static const char *sd_state_name(enum SDCardStates state) { static const char *state_name[] = { @@ -968,8 +981,9 @@ static bool address_in_range(SDState *sd, const char *desc, static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) { - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s\n", - req.cmd, sd_state_name(sd->state)); + qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s (spec %s)\n", + req.cmd, sd_state_name(sd->state), + sd_version_str(sd->spec_version)); return sd_illegal; } From patchwork Mon May 30 19:37:55 2022 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: 12864903 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 C6904C433EF for ; Mon, 30 May 2022 19:45:42 +0000 (UTC) Received: from localhost ([::1]:36888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlKf-0007tX-M9 for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:45:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlED-0006w2-Ln; Mon, 30 May 2022 15:39:02 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:53208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlEB-0008Du-OU; Mon, 30 May 2022 15:39:01 -0400 Received: by mail-pj1-x102d.google.com with SMTP id gd1so3595015pjb.2; Mon, 30 May 2022 12:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g/fUXjzaltH1avxyUdAnsl5PWfk9MZbsOrfjIpDgLv4=; b=TXUBozCUrpoIP6RnuSWz86zeZtz3DjR904S86tzxBFJs+rPZFZgdeYIvwa9WjCIRAO dJ7IAWaOofDfIat8TcXYY2yhbYnYB+/K88bLgnuoTqcdJtFp4Ki1nEVmBl0E9uoiHYMO CD4byqQgAbF+BX6f5I72Swb8pF1hpRPWz1WjsT3PdNbgk0MGmL5WjxStU0RBut01U5PH U9LfbHX8iK1Q4zZBZWNX6Uik5x+BTkQwySWgxQ6vlheT2ANaQvbx3+OIvoB1XpTfn7eE a/Mwoa3Nif+9zdrBk/68yo8+kcinETQI6zLyFw6kPZcF6I67u89QODzPHcX/D++yEh8A W2Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g/fUXjzaltH1avxyUdAnsl5PWfk9MZbsOrfjIpDgLv4=; b=vyfxx19Crj2YM3EA+tFCgkglNxkH65JZEKrFvQFtk+boLMab66Zz9QlyRVeuFVPvOw qPOlX+bq9RFw3LcpyUJuBW4AxU5QbRLCcToI89A3/3+BzPRR5HXvRNXxJiN6HhmFdB3T QgvaEJICIfw18b0l0urXGxnhdTyknlzrynzaBy0s9fU0DMxpGbr2Qih4wMkFg52G7sCg 8JOm4OIIdq4d1UdH3H2XLHb1jH8wA/S67tlU0jiUTVoUihLQNkTtOyoYGZ4G+iWpUPG6 bDmJqpFMOfqf4+zdg4VYMoBj9UVH1Vl190zY0vqUxRphgUqefF9HkA88/Y3JJSEhEGiN gEbg== X-Gm-Message-State: AOAM531LAbJFNHLbXceeyX3DrvccUxyG7PwfGSFIf9U4WHes//bTxzu+ NigX+Sjd+JzQ//IGCTNf1yIKrRXFe9w= X-Google-Smtp-Source: ABdhPJxdMyC/6rMAQ5rRrjPPhEmugutiRqylUcTfD7beooVdsSfb4DEbt1EB7fNFDqWsmykTN7TX4g== X-Received: by 2002:a17:902:ecc6:b0:162:27bd:4a4c with SMTP id a6-20020a170902ecc600b0016227bd4a4cmr39582895plh.97.1653939537895; Mon, 30 May 2022 12:38:57 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id p22-20020a63f456000000b003fae31058e2sm8889232pgk.29.2022.05.30.12.38.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:38:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 04/25] hw/sd: Move proto_name to SDProto structure Date: Mon, 30 May 2022 21:37:55 +0200 Message-Id: <20220530193816.45841-5-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Introduce a new structure to hold the bus protocol specific fields: SDProto. The first field is the protocol name. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-4-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 35 +++++++++++++++++++++++++++-------- include/hw/sd/sd.h | 2 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b3e61b9f84..953dbbd7ae 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -87,6 +87,10 @@ enum SDCardStates { sd_disconnect_state, }; +typedef struct SDProto { + const char *name; +} SDProto; + struct SDState { DeviceState parent_obj; @@ -137,7 +141,6 @@ struct SDState { qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; - const char *proto_name; bool enable; uint8_t dat_lines; bool cmd_line; @@ -145,6 +148,13 @@ struct SDState { static void sd_realize(DeviceState *dev, Error **errp); +static const struct SDProto *sd_proto(SDState *sd) +{ + SDCardClass *sc = SD_CARD_GET_CLASS(sd); + + return sc->proto; +} + static const char *sd_version_str(enum SDPhySpecificationVersion version) { static const char *sdphy_version[] = { @@ -981,8 +991,8 @@ static bool address_in_range(SDState *sd, const char *desc, static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) { - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s (spec %s)\n", - req.cmd, sd_state_name(sd->state), + qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong state: %s (spec %s)\n", + sd_proto(sd)->name, req.cmd, sd_state_name(sd->state), sd_version_str(sd->spec_version)); return sd_illegal; @@ -997,7 +1007,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) * However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd != 55 || sd->expecting_acmd) { - trace_sdcard_normal_command(sd->proto_name, + trace_sdcard_normal_command(sd_proto(sd)->name, sd_cmd_name(req.cmd), req.cmd, req.arg, sd_state_name(sd->state)); } @@ -1562,7 +1572,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { - trace_sdcard_app_command(sd->proto_name, sd_acmd_name(req.cmd), + trace_sdcard_app_command(sd_proto(sd)->name, sd_acmd_name(req.cmd), req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |= APP_CMD; switch (req.cmd) { @@ -1856,7 +1866,7 @@ void sd_write_byte(SDState *sd, uint8_t value) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return; - trace_sdcard_write_data(sd->proto_name, + trace_sdcard_write_data(sd_proto(sd)->name, sd_acmd_name(sd->current_cmd), sd->current_cmd, value); switch (sd->current_cmd) { @@ -2012,7 +2022,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; - trace_sdcard_read_data(sd->proto_name, + trace_sdcard_read_data(sd_proto(sd)->name, sd_acmd_name(sd->current_cmd), sd->current_cmd, io_len); switch (sd->current_cmd) { @@ -2131,6 +2141,14 @@ void sd_enable(SDState *sd, bool enable) sd->enable = enable; } +static const SDProto sd_proto_spi = { + .name = "SPI", +}; + +static const SDProto sd_proto_sd = { + .name = "SD", +}; + static void sd_instance_init(Object *obj) { SDState *sd = SD_CARD(obj); @@ -2149,9 +2167,10 @@ static void sd_instance_finalize(Object *obj) static void sd_realize(DeviceState *dev, Error **errp) { SDState *sd = SD_CARD(dev); + SDCardClass *sc = SD_CARD_GET_CLASS(sd); int ret; - sd->proto_name = sd->spi ? "SPI" : "SD"; + sc->proto = sd->spi ? &sd_proto_spi : &sd_proto_sd; switch (sd->spec_version) { case SD_PHY_SPECv1_10_VERS diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 47360ba4ee..0d94e1f346 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -124,6 +124,8 @@ struct SDCardClass { void (*enable)(SDState *sd, bool enable); bool (*get_inserted)(SDState *sd); bool (*get_readonly)(SDState *sd); + + const struct SDProto *proto; }; #define TYPE_SD_BUS "sd-bus" From patchwork Mon May 30 19:37:56 2022 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: 12864902 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 E834BC433EF for ; Mon, 30 May 2022 19:45:32 +0000 (UTC) Received: from localhost ([::1]:36572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlKW-0007f4-0f for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:45:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlEM-0006zf-3s; Mon, 30 May 2022 15:39:11 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:37658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlEK-0008F5-KD; Mon, 30 May 2022 15:39:09 -0400 Received: by mail-pj1-x102b.google.com with SMTP id m14-20020a17090a414e00b001df77d29587so206290pjg.2; Mon, 30 May 2022 12:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RDRU+6JkBy4sLgS3aQWSiZOqQJUAYugjHx5ft3m2OBI=; b=Iq8oQ7vOGMVPvFPsSiFi3DKcMPC6Nh2/RIzLiQnwrg7e0onNz9h2MBPy5jB4ipQpjr x4K5J3uRzdCJVqTTjCH9cgXY226kxExA8Q6vXbelMINETMXKzcLtRGwppXzYDdh8RFuj CucWFyggOApl0xk1Uh+/ven0Pvn72N950NMxmcUfMnA3Lr+dyrh4esoiQMvK5pPnW/j7 IF86arPZwuVUMmo/om3Bo9B8jxB2ZzW99pbfAvNS/SP33o+d28iTtaG6sxGFFDfT7oxG hL0gbwWrygzxWWlPvrIZ8pq7Rs5VvRGEgW5D/XxYGlJHLuh7Hf7WMbaw6WYojgJw3teT BA0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RDRU+6JkBy4sLgS3aQWSiZOqQJUAYugjHx5ft3m2OBI=; b=UCEssiMY4QCSi0mEmk3AB86hqN0mwivMtamq/oI+PGqd9Zj4R5AT0+0ZFMcPuA0Jsr jmc19fampAHcIuWTdkpb/IDGC7IRQDUZMV5VRGacliHvtUhtQqDrAaVc0drovdW+RP9R kOwtZ9yCo5dlvHRwwpugkdXOgdGIhC6Zt2e1ZRxU60R3sS2Fq8aAzQIvq88iVXyQ865E yUSQ9pFSxntlLMqBavXNRnQ5KoQHNVUJJsFgdhvPJDmhvqQywGFAqbCLOjI1tAuR/61d px98eH1JID/OM5/Hil8dAPMCBdYPq+AoZZqzAgz1qR7wbkNRZjABUk5wNLsAk/g8vmwt e8aw== X-Gm-Message-State: AOAM531O6XJFXowgWp62ou7u07PmMLnlUBJ4SBX1CKN+qj0WV+kqIXpa irDyxjP0yHvs3kmtyh59wOMp8tP8g6M= X-Google-Smtp-Source: ABdhPJwhIpDzpVgAjakM8JpLACxBFwRJrkx9MBtmuMXSPzlRaNLREVt31mifg6D2tpCrAxpT7eMU3g== X-Received: by 2002:a17:90a:4587:b0:1de:c6ee:80f with SMTP id v7-20020a17090a458700b001dec6ee080fmr24515208pjg.196.1653939546703; Mon, 30 May 2022 12:39:06 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id y13-20020a170902ed4d00b0015ea4173bd6sm197555plb.195.2022.05.30.12.39.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 05/25] hw/sd: Introduce sd_cmd_handler type Date: Mon, 30 May 2022 21:37:56 +0200 Message-Id: <20220530193816.45841-6-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Add 2 command handler arrays in SDProto, for CMD and ACMD. Have sd_normal_command() / sd_app_command() use these arrays: if an command handler is registered, call it, otherwise fall back to current code base. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-5-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 953dbbd7ae..ed63528615 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -87,8 +87,12 @@ enum SDCardStates { sd_disconnect_state, }; +typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); + typedef struct SDProto { const char *name; + sd_cmd_handler cmd[SDMMC_CMD_MAX]; + sd_cmd_handler acmd[SDMMC_CMD_MAX]; } SDProto; struct SDState { @@ -1031,6 +1035,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_illegal; } + if (sd_proto(sd)->cmd[req.cmd]) { + return sd_proto(sd)->cmd[req.cmd](sd, req); + } + switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ case 0: /* CMD0: GO_IDLE_STATE */ @@ -1575,6 +1583,11 @@ static sd_rsp_type_t sd_app_command(SDState *sd, trace_sdcard_app_command(sd_proto(sd)->name, sd_acmd_name(req.cmd), req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |= APP_CMD; + + if (sd_proto(sd)->acmd[req.cmd]) { + return sd_proto(sd)->acmd[req.cmd](sd, req); + } + switch (req.cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ if (sd->spi) { From patchwork Mon May 30 19:37:57 2022 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: 12864908 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 D6FE1C433EF for ; Mon, 30 May 2022 19:50:48 +0000 (UTC) Received: from localhost ([::1]:46396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlPb-0005x1-TX for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:50:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlEU-0007BY-Vk; Mon, 30 May 2022 15:39:20 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:45882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlET-0008Gv-7Q; Mon, 30 May 2022 15:39:18 -0400 Received: by mail-pg1-x532.google.com with SMTP id a63so4705880pge.12; Mon, 30 May 2022 12:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=htoy1+loy6kPJWKosohY2nohbhdVtDpnoBU7PmIuli8=; b=GGJ7MGvc3WA9oHu/FBuyNJYnKNgZ2SkA2VGpsNIGcCxYWQQeDFGzpqfJSrp6Ai9WKG GI0F80yw79iS1WSVhKZ7TDCd7jierZgnxtMx45A7X/jnNkooU4LSff1axz8Pzb8gqNt+ UFf08msCfI9sEiCUMDV/gq/dGVaEyAvTO9qNBfdvvvZsezSpz+XmRF2IMXJj0WoOBvYl BPIdfW7Z1JW9MBSlULl4N9IbJaeTM9ftn26JhAFN1P0FjKj863vnNurBCFB+KIvOnd4s YNckGLFFaFSihNBObjoxC9kr6vtqqLihZaIFElcyzJp9hX2mPNTTO4JKxGcHbakKYVoD 4zUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=htoy1+loy6kPJWKosohY2nohbhdVtDpnoBU7PmIuli8=; b=7eZkHbVxLC2cSiRioO0SbbXoDpyOE1CKAOINLn4WQ41z4/thk0z481HVnHBzoh8bel vel4YOBSW8HTKGimWOQ1W06g5BmnVSCM0a/O5wznYKuglksJ54W6M95wYWOyw+xtQvSP T6CFIOb45itcP0JUHcqLpTpvZryH/vy7f3DPYBYubE5TrJ6QHUzpkted6VLJAhZh2Y0h +WKnx8a3RuEU19SAwOsYzIP+k7q2pqciO7DaBzziR8J+XCPsghP3qC5wlwd/Iksj/5Ao bSOL3yfAoRAL5yjPiXmHPpkKiEaMmrJb/6KF55Fwxh1cnajwttLL+m27Jkh+D2nbs3MH L7eQ== X-Gm-Message-State: AOAM530rSBB15SzRydMSgUytxWfshGMPuSC084LK4WQBH615NOHtOHTD Plw7eYF1qUnWWfss74Wu6clOQAu43ks= X-Google-Smtp-Source: ABdhPJybmg9WgakZcfzcdkhPRG0Rdpv5HRDMG777J9iiE83ocidjl9X8Cfo5v4dty4sL+o/6FNsNRw== X-Received: by 2002:a05:6a02:10d:b0:381:f4c8:ad26 with SMTP id bg13-20020a056a02010d00b00381f4c8ad26mr49199622pgb.135.1653939555486; Mon, 30 May 2022 12:39:15 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id l5-20020a17090a598500b001e310303275sm54897pji.54.2022.05.30.12.39.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 06/25] hw/sd: Add sd_cmd_illegal() handler Date: Mon, 30 May 2022 21:37:57 +0200 Message-Id: <20220530193816.45841-7-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Log illegal commands as GUEST_ERROR. Note: we are logging back the SDIO commands (CMD5, CMD52-54). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-6-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 62 +++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ed63528615..bda24bc042 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1002,6 +1002,15 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) 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", + sd_proto(sd)->name, req.cmd, + sd_version_str(sd->spec_version)); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1054,15 +1063,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 1: /* CMD1: SEND_OP_CMD */ - if (!sd->spi) - goto bad_cmd; - sd->state = sd_transfer_state; return sd_r1; case 2: /* CMD2: ALL_SEND_CID */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_ready_state: sd->state = sd_identification_state; @@ -1074,8 +1078,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 3: /* CMD3: SEND_RELATIVE_ADDR */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_identification_state: case sd_standby_state: @@ -1089,8 +1091,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 4: /* CMD4: SEND_DSR */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_standby_state: break; @@ -1100,9 +1100,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 5: /* CMD5: reserved for SDIO cards */ - return sd_illegal; - case 6: /* CMD6: SWITCH_FUNCTION */ switch (sd->mode) { case sd_data_transfer_mode: @@ -1118,8 +1115,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 7: /* CMD7: SELECT/DESELECT_CARD */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_standby_state: if (sd->rca != rca) @@ -1249,8 +1244,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 15: /* CMD15: GO_INACTIVE_STATE */ - if (sd->spi) - goto bad_cmd; switch (sd->mode) { case sd_data_transfer_mode: if (sd->rca != rca) @@ -1303,7 +1296,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - goto bad_cmd; + return sd_invalid_state_for_cmd(sd, req); } if (sd->state == sd_transfer_state) { sd->state = sd_sendingdata_state; @@ -1314,7 +1307,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 23: /* CMD23: SET_BLOCK_COUNT */ if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - goto bad_cmd; + return sd_invalid_state_for_cmd(sd, req); } switch (sd->state) { case sd_transfer_state: @@ -1357,8 +1350,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 26: /* CMD26: PROGRAM_CID */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_transfer_state: sd->state = sd_receivingdata_state; @@ -1508,15 +1499,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 52 ... 54: - /* CMD52, CMD53, CMD54: reserved for SDIO cards - * (see the SDIO Simplified Specification V2.0) - * Handle as illegal command but do not complain - * on stderr, as some OSes may use these in their - * probing for presence of an SDIO card. - */ - return sd_illegal; - /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ switch (sd->state) { @@ -1557,19 +1539,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 58: /* CMD58: READ_OCR (SPI) */ - if (!sd->spi) { - goto bad_cmd; - } return sd_r3; case 59: /* CMD59: CRC_ON_OFF (SPI) */ - if (!sd->spi) { - goto bad_cmd; - } return sd_r1; default: - bad_cmd: qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); return sd_illegal; } @@ -2156,10 +2131,25 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", + .cmd = { + [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, + }, }; static const SDProto sd_proto_sd = { .name = "SD", + .cmd = { + [1] = sd_cmd_illegal, + [5] = sd_cmd_illegal, + [52 ... 54] = sd_cmd_illegal, + [58] = sd_cmd_illegal, + [59] = sd_cmd_illegal, + }, }; static void sd_instance_init(Object *obj) From patchwork Mon May 30 19:37:58 2022 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: 12864900 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 62AA1C433EF for ; Mon, 30 May 2022 19:41:46 +0000 (UTC) Received: from localhost ([::1]:56618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlGr-0001wZ-F6 for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:41:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlEe-0007Ky-K4; Mon, 30 May 2022 15:39:30 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:40951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlEc-0008Jn-1D; Mon, 30 May 2022 15:39:27 -0400 Received: by mail-pg1-x534.google.com with SMTP id x12so10866736pgj.7; Mon, 30 May 2022 12:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e9iS3syVNTGY9f8bav4NL3gx/ZBjKrH1QuSH4Tv1Ag0=; b=R9Yz3cIKXhKw53+S9lt/uXc9PueL+E3rfVqulJo4868+qYo08axpd7SsDqeOMKRTOK x2OchxUNmM+eZKxM0LdNmpu9H5CGMNqgvrfNznuT/H3cI56P1deukoNnTA164Triew+T qcTuO66XSXeHeBWtmR0zc8E9vVLrKTXeHht7JYM7G1wBQFvlME4x4JB58jnsEhns+tTW BipUj9fR8OyvAFqugUDybqzbD7KDpK/AjyabG922gymPjKyEVN0O+OlnNygnQyDNjCpe azDS2eRvQ68EaVHj6gkO4kQJrmUlaDkhDS4fG1c2b1yrUzncagAYHQBY3uY/eXL8WkDA lEkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e9iS3syVNTGY9f8bav4NL3gx/ZBjKrH1QuSH4Tv1Ag0=; b=VWd5ZYvaC5Z7r9RSFI7X1yT71n5v2fATtkxk32xDSo0Qcyk4sKrTybni+HuEQN35HC Jr+lsbQTKRmY4qTWMOdeUAPe5St7s36d4mFgvQasTcKbfgyfhm6fOEmUWu6IlgTPcIKt ackXlae2uOwoEV+C/M01xsU+6mvrq7S3Ew7c1vRVtlS+ht3n/WeA+usNE7CczQE69leB zZfyzpNfaGpUlxo2gRA5A/OnhsyEqeAeoDrdntFrCgFTycyu7eLUu7Q3pLoaHT5JVMW2 OND3Rb6b8hIp8LBBN9Wehxn/mSPQxN9IchZneQpS9cCfhQkJlsML/jKGHMJm7IhTklmR ThGw== X-Gm-Message-State: AOAM530Roftjo7Miug5vHk1bNriIVv1/XphhC80SfatMDtQ7ZcYSqkw6 zjDETcBl45Qv5jQGbm7fSlKoHWWSkjU= X-Google-Smtp-Source: ABdhPJx8mTB/ay01HHdAdPoy7Ii4Y9hgY+NijyuAy/sLoUBZYV2OBwrciX9F05/lH8KX1my/KXVVLA== X-Received: by 2002:a05:6a00:10d0:b0:4f7:5af4:47b6 with SMTP id d16-20020a056a0010d000b004f75af447b6mr58591902pfu.6.1653939564231; Mon, 30 May 2022 12:39:24 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id w10-20020a170902904a00b0015e8d4eb29csm4297505plz.230.2022.05.30.12.39.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 07/25] hw/sd: Add sd_cmd_unimplemented() handler Date: Mon, 30 May 2022 21:37:58 +0200 Message-Id: <20220530193816.45841-8-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé [ clg: Fix redundant assignment of .cmd ] Message-Id: <20210624142209.1193073-7-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index bda24bc042..e018498b10 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1011,6 +1011,15 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) return sd_illegal; } +/* Commands that are recognised but not yet implemented. */ +static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n", + sd_proto(sd)->name, req.cmd); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1565,9 +1574,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, switch (req.cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ - if (sd->spi) { - goto unimplemented_spi_cmd; - } switch (sd->state) { case sd_transfer_state: sd->sd_status[0] &= 0x3f; @@ -1698,12 +1704,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, default: /* Fall back to standard commands. */ return sd_normal_command(sd, req); - - unimplemented_spi_cmd: - /* Commands that are recognised but not yet implemented in SPI mode. */ - qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", - req.cmd); - return sd_illegal; } qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", req.cmd); @@ -2139,6 +2139,9 @@ static const SDProto sd_proto_spi = { [26] = sd_cmd_illegal, [52 ... 54] = sd_cmd_illegal, }, + .acmd = { + [6] = sd_cmd_unimplemented, + }, }; static const SDProto sd_proto_sd = { From patchwork Mon May 30 19:37:59 2022 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: 12864904 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 6B060C433F5 for ; Mon, 30 May 2022 19:45:43 +0000 (UTC) Received: from localhost ([::1]:36972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlKg-0007x8-DG for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:45:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlEn-0007RE-QQ; Mon, 30 May 2022 15:39:39 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:42776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlEl-0008KT-3H; Mon, 30 May 2022 15:39:37 -0400 Received: by mail-pj1-x102f.google.com with SMTP id d12-20020a17090abf8c00b001e2eb431ce4so183668pjs.1; Mon, 30 May 2022 12:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rg50Y+o/eUBM4CXukBeXYZLp2dR7HPz/PEGiozmLP6Y=; b=JPSP8o0dKou9uVyq3AFeQ53pDBjfFbAHq27cLZmArPZK3vKbM8UZV568fS6TntPiHX IqPqUEm/ZBRzkWUpiuS8txARfpAMGovGYwEl1LBXZDHJ3Xdnz88PcfXLaQ3ObWj386yX rcaSMMt9tsbxneEuAjrmmiGfY949MixeVMWFDn3AvEdiFVFMrIFZvKhZvwU1DugkgC1t f5kg7kwYUuPpUPj2nI6OAFothiVLyLkx5mWklRLmylAdVsIwOfXt86OzVZodctm14BJt Qkp+E1hknZEZuRJSFkxxXjB0CpURzNNqBSBieqsdsqTWt4lH/tfHHUCeRHKtyc2FNDhx 2RXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rg50Y+o/eUBM4CXukBeXYZLp2dR7HPz/PEGiozmLP6Y=; b=EV9zO1k8EQPmFMui+x+6MoVOX12NlnGjTTxNqzbnN9cIi0dLwKa+YZmIgd2nXnLeIH mM6qyOKPcEh1Wc/IqEBiTQ9uqo01kS4Rgk4OO5U4jw1ojNiioeylYguvvL9ChxES+ySI 1NP91P7cO4KfqXXVRqgwuvLcV5LGruopA1tCjY3Du08ZhilP1GJ/DYQ+FaiHg9dEBWS3 dy75ABGq+7w+t9Zcgo4ufdasOxECRvuJc8GW6x5D6e/LFcRTsqL0lP6bHESb4jLfA/SA v86MIfrH0DUPJFFSfiyaCl8m3onwfoFQr9WuQsbS1Mbe7qhbA9thIt6KOjrao9LXtrtk afJw== X-Gm-Message-State: AOAM532CYLpgzKjtZ/CzhLiXbJyqZda9ktzvc21r9IQ4g0o9ijVdix3o 6eJZ/K6/vAlTJWd/zOboXX11Co5PtU4= X-Google-Smtp-Source: ABdhPJwSa4+x/hTMTq1v9eukOa3b88lWiYE7ogSHRQG5YPR/DBvH1+u/FxvGr04IMmiaaZkgsqZ4kQ== X-Received: by 2002:a17:903:249:b0:163:6dc0:b8b3 with SMTP id j9-20020a170903024900b001636dc0b8b3mr24575333plh.24.1653939573124; Mon, 30 May 2022 12:39:33 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id q44-20020a17090a17af00b001cd4989ff41sm85671pja.8.2022.05.30.12.39.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 08/25] hw/sd: Add sd_cmd_GO_IDLE_STATE() handler Date: Mon, 30 May 2022 21:37:59 +0200 Message-Id: <20220530193816.45841-9-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-8-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e018498b10..22405e8bb6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1020,6 +1020,16 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) +{ + if (sd->state != sd_inactive_state) { + sd->state = sd_idle_state; + sd_reset(DEVICE(sd)); + } + + return sd->spi ? sd_r1 : sd_r0; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1059,18 +1069,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 0: /* CMD0: GO_IDLE_STATE */ - switch (sd->state) { - case sd_inactive_state: - return sd->spi ? sd_r1 : sd_r0; - - default: - sd->state = sd_idle_state; - sd_reset(DEVICE(sd)); - return sd->spi ? sd_r1 : sd_r0; - } - break; - case 1: /* CMD1: SEND_OP_CMD */ sd->state = sd_transfer_state; return sd_r1; @@ -2132,6 +2130,7 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { + [0] = sd_cmd_GO_IDLE_STATE, [2 ... 4] = sd_cmd_illegal, [5] = sd_cmd_illegal, [7] = sd_cmd_illegal, @@ -2147,6 +2146,7 @@ static const SDProto sd_proto_spi = { static const SDProto sd_proto_sd = { .name = "SD", .cmd = { + [0] = sd_cmd_GO_IDLE_STATE, [1] = sd_cmd_illegal, [5] = sd_cmd_illegal, [52 ... 54] = sd_cmd_illegal, From patchwork Mon May 30 19:38:00 2022 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: 12864915 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 6888AC433EF for ; Mon, 30 May 2022 19:56:56 +0000 (UTC) Received: from localhost ([::1]:35880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlVX-0001R5-E6 for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:56:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlEv-0007ll-Af; Mon, 30 May 2022 15:39:45 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:45906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlEt-0008LQ-EX; Mon, 30 May 2022 15:39:44 -0400 Received: by mail-pl1-x62f.google.com with SMTP id q18so11038372pln.12; Mon, 30 May 2022 12:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hc8op+xHNyF3R11bJslh7S9ghBerJPL5Ix/mS+aQ9B4=; b=fdxSyGd1UgkkzqAw3L2L5Kn8Gmt8ogMwHczY9a/B9f+RO+eJA3XduNjAolN0clPBHR mDKvM8bP9zMGLX+zgd3NCztjw/0Is/YasqhPJjAum9HFZn8DqnCtdtYPNxWTS2cQuW6o 3wsDbl8GhzsmGrQkPSdHyMy8rQsppKgSn3AIANFwRlKNev0IIM+oIUQx3iY/HFVm92mA 6H7lDPTxmS7pmopG9xU4CVM/SFMXLE0UC1Ss+JZSTlxYC+EhoxBoYipaKE0H3h/3dZe+ NqNRht43+QOl4LV60l5S0aJAIRkVNBLThTDh/TW0zkVJICqVRID3E2yO+SVbclanpdsw PZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hc8op+xHNyF3R11bJslh7S9ghBerJPL5Ix/mS+aQ9B4=; b=HVEAx+WrSeeKknGVpeNkT2VQEcsOYho6aDT2LauD1z7BMod48+W3K/RUWSHWG0xdui 2Fd+WI7fYZResLk/l/O7KUPTPeqCmMamPpFs9KkaZU2w4suzfYXqYnO59lO1MF0YSAEE NHZpQCeHMI7JUHFNKOYZGEcsU8q+PefFNUDOYYheBJf5CMX+i/fiWfCYwBWgmMqOGFOB 9WEIAwWmUSyMOckuOwI5yBP51BFfAmDhjzHhgL+IpHiSjG04+Fgrr7qTt1uIeT4MsCOr t4V7rNTvmb97O/BjnTHFnJ8z+6m6lfVz7oQKqllPkeENcv8v2xuCJayrUMLoK7FL4Y/Y E1SQ== X-Gm-Message-State: AOAM531hONA/DnBX46HW9wEfvK94RTbgBHIosq3iMWYGnaDelr0CItmh R+jlEm0U1sZe+/fBX3nKs+EKdGTRIao= X-Google-Smtp-Source: ABdhPJyRP1OBTChenIjMfYlytpYOtwSGQET7+2rDpEFKHqnsSIC/1/2fvh/4gXQ9M8vSUgcNoAWxOg== X-Received: by 2002:a17:90a:5b03:b0:1df:86d4:ba27 with SMTP id o3-20020a17090a5b0300b001df86d4ba27mr24372368pji.124.1653939581677; Mon, 30 May 2022 12:39:41 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id a21-20020a170903101500b0015e8d4eb26bsm5184960plb.181.2022.05.30.12.39.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 09/25] hw/sd: Add sd_cmd_SEND_OP_CMD() handler Date: Mon, 30 May 2022 21:38:00 +0200 Message-Id: <20220530193816.45841-10-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé [ clg: Update cmd_abbrev ] Message-Id: <20210624142209.1193073-9-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 18 +++++++++--------- hw/sd/sdmmc-internal.c | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 22405e8bb6..ac81e1c667 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1030,6 +1030,13 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) return sd->spi ? sd_r1 : sd_r0; } +static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) +{ + sd->state = sd_transfer_state; + + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1069,10 +1076,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 1: /* CMD1: SEND_OP_CMD */ - sd->state = sd_transfer_state; - return sd_r1; - case 2: /* CMD2: ALL_SEND_CID */ switch (sd->state) { case sd_ready_state: @@ -1622,11 +1625,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, break; case 41: /* ACMD41: SD_APP_OP_COND */ - if (sd->spi) { - /* SEND_OP_CMD */ - sd->state = sd_transfer_state; - return sd_r1; - } if (sd->state != sd_idle_state) { break; } @@ -2131,6 +2129,7 @@ static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { [0] = sd_cmd_GO_IDLE_STATE, + [1] = sd_cmd_SEND_OP_CMD, [2 ... 4] = sd_cmd_illegal, [5] = sd_cmd_illegal, [7] = sd_cmd_illegal, @@ -2140,6 +2139,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [6] = sd_cmd_unimplemented, + [41] = sd_cmd_SEND_OP_CMD, }, }; diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c index 2053def3f1..8648a7808d 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", + [0] = "GO_IDLE_STATE", [1] = "SEND_OP_CMD", [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 May 30 19:38:01 2022 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: 12864907 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 1689BC433F5 for ; Mon, 30 May 2022 19:48:23 +0000 (UTC) Received: from localhost ([::1]:43078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlNF-0003hQ-5U for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:48:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlF3-0008Dq-M1; Mon, 30 May 2022 15:39:53 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:45007) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlF2-0008M5-3Q; Mon, 30 May 2022 15:39:53 -0400 Received: by mail-pl1-x62d.google.com with SMTP id h1so1844542plf.11; Mon, 30 May 2022 12:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JuLLPKf5etqKtzMV1e+zTPwwL4KsbIS19QbNZINfse4=; b=ZRqod1Q7YmTBj452aoyNRhjZlArBNQvT+74bq8kRvJLa1WQIVHFxsJUTn9bMWVL5m8 Dh9drbe17v49ilUkEn1hUIj8fIZ++ngCw+50z9harj2uT4gW85vmZXxYTDTHz/S5oVkc sNje+uxQDFnc3Eq7vSOHhUk5h3K0N0fYbApiK9/7sydQVMBCEULWuDUuI6WjevV8pV7o 8Na6UlZduzLQcrOqGYYkJ13bwe7sK2my61DPVqovhe+ZEMUuy29ReTQx8+ZdHT3FYQLF f+OLifeemwM1cehjUox58CBP2RbieP2CpDdxzGNyH6oYCcWjsbIvEKEuMZZ7TQeyjB5Q 2qtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JuLLPKf5etqKtzMV1e+zTPwwL4KsbIS19QbNZINfse4=; b=hTrLTCCT70VxB2UE6wCnMFgbBZJxSXo7a4/QZ98GmteFKssgwibNKraXf4Hzeaxt05 bn94UkNjI9yKB81psmPBz7Aw/zKUT9IZ7bAHD/GzuYMeW0LqPKexhZtcYJxLcDN7zFbJ 3KxN07Grojc644sMtOF4yak9uCS2+GDe1p9iMiy4JBdx5Jg86w3CWB3Dzx9TJHPChfpH 2tOMjSXqjfxq5gbrifUIyl85d+5em4+BADP3B3B2wPykBlNQfvfG60Gvvlf2jsXiSisi 6FCLWkIt7Z6+3XDaOiLjdVaGKrwSnNOFO8Jpw4tyqCDbBWO8sqEQT9DIsoKKMQF6blJS XN5g== X-Gm-Message-State: AOAM533d8CUhKmYqY5uAk4RjmWgNnNB7QSDYdY5pCSjBaJ/UdsMNR0K3 pEMvzop7g8xtQZnZpxRDve8QkIhG6L0= X-Google-Smtp-Source: ABdhPJw9Z08wzNeAyl4y/l0TM/N+Uc/nSItxjUnOCOM9ZZVMviCPqeU9Gg4I0v+WfeFiiNVbiZkLbA== X-Received: by 2002:a17:902:9a8c:b0:162:22ff:494e with SMTP id w12-20020a1709029a8c00b0016222ff494emr40745614plp.77.1653939590307; Mon, 30 May 2022 12:39:50 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id d24-20020a170902729800b00161ea00350bsm9601596pll.277.2022.05.30.12.39.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 10/25] hw/sd: Add sd_cmd_ALL_SEND_CID() handler Date: Mon, 30 May 2022 21:38:01 +0200 Message-Id: <20220530193816.45841-11-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-10-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ac81e1c667..b56b8fea41 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1037,6 +1037,17 @@ static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) return sd_r1; } +static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) +{ + if (sd->state != sd_ready_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_identification_state; + + return sd_r2_i; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1076,17 +1087,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 2: /* CMD2: ALL_SEND_CID */ - switch (sd->state) { - case sd_ready_state: - sd->state = sd_identification_state; - return sd_r2_i; - - default: - break; - } - break; - case 3: /* CMD3: SEND_RELATIVE_ADDR */ switch (sd->state) { case sd_identification_state: @@ -2148,6 +2148,7 @@ static const SDProto sd_proto_sd = { .cmd = { [0] = sd_cmd_GO_IDLE_STATE, [1] = sd_cmd_illegal, + [2] = sd_cmd_ALL_SEND_CID, [5] = sd_cmd_illegal, [52 ... 54] = sd_cmd_illegal, [58] = sd_cmd_illegal, From patchwork Mon May 30 19:38:02 2022 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: 12864911 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 91276C433F5 for ; Mon, 30 May 2022 19:52:05 +0000 (UTC) Received: from localhost ([::1]:51464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlQq-0001BI-NZ for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:52:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFC-0000GR-A0; Mon, 30 May 2022 15:40:02 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:56058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFA-0008MJ-Kt; Mon, 30 May 2022 15:40:01 -0400 Received: by mail-pj1-x102a.google.com with SMTP id n10so11742716pjh.5; Mon, 30 May 2022 12:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ExL56MzpCj++F0LIP8Goq8EPnsP+R6HFgjnAJW1UmM=; b=Cxnz2D88ORkUjbW/NGUvUNNYUVDYnANua15RSoKo4WOhP5hpb5jCUUiWiBG/+U0UY4 t4KPFDPy1uLmWNBvBFeomb+G2df6nG03Q0E4RByQ7HCaqKWwoE9Lc/gcFk4kPnoems9D PC/+0nq2s/md1jYYqZb1S55YUwW6KN4uRBSE4c+pW5FG8tZJVJyAFgWd4f2QuTQodfAO gYjiNddRPYznTT8PnP65akyFRofSbkPnXrVJAioZ+rhWfjqUuicnPujuSl+OZpeoJ9zk 25NR71K6+Zwet1NZ7Z47C6PBJ1KBMesDG9PlYEHGYRl9L8755Hc/vNbjLUrTdoZo+ipJ 4lBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ExL56MzpCj++F0LIP8Goq8EPnsP+R6HFgjnAJW1UmM=; b=VCXGxSV8aSbq+PC8aGGbDDn81e2nri958D91bzNUTcmHV29/zy7v5d8jN1N3UW+mPj mDe+avjcyo319++jm96JeQJWYqDI6eylw5JylQdCJbj1w0tkxLKGI7c+s3TEAObliVkq iLz4hbn8l0FI1EHfP67+VKajibbBfNFzG4CN3Kmlikch+9h7AP4wjxlfLBiTfO63WU5k 7vIZuVznxX+qb7COeRSxJ8xb5dBupjYA+Pk0AHt5mpr9yvwrQ1pqk6Wp/bB6Q0mEOO05 AVU2BO9Tyo1c3hKdEP4c7QFY+ohTQCmyiWGVttkp/ZtmoOh7/c1eSGbkRhiIACulxYPZ NKTg== X-Gm-Message-State: AOAM533buxuJmwZR+VaFnh/C6suoHg6uYVV8SfnMQNolR4f5clz/Csia QvXJiXvyc2MBYdZySshZlqDNqMlypxg= X-Google-Smtp-Source: ABdhPJyPT0whsWu7revV6CoMiOi8S8bfXuR9sC5CB57Jvc3zsd7ryI/gzpvQ3+mhQmJ31g+tgyQh7w== X-Received: by 2002:a17:90a:ba15:b0:1cb:be7d:bbca with SMTP id s21-20020a17090aba1500b001cbbe7dbbcamr24348284pjr.143.1653939598913; Mon, 30 May 2022 12:39:58 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id i186-20020a6387c3000000b003fba6db1b50sm7059321pge.85.2022.05.30.12.39.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:39:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , Bin Meng Subject: [PATCH v2 11/25] hw/sd: Add sd_cmd_SEND_RELATIVE_ADDR() handler Date: Mon, 30 May 2022 21:38:02 +0200 Message-Id: <20220530193816.45841-12-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng Message-Id: <20210624142209.1193073-11-f4bug@amsat.org> Signed-off-by: Cédric Le Goater --- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b56b8fea41..2fe05c5a3d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1048,6 +1048,20 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) return sd_r2_i; } +static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_identification_state: + case sd_standby_state: + sd->state = sd_standby_state; + sd_set_rca(sd); + return sd_r6; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1087,19 +1101,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 3: /* CMD3: SEND_RELATIVE_ADDR */ - switch (sd->state) { - case sd_identification_state: - case sd_standby_state: - sd->state = sd_standby_state; - sd_set_rca(sd); - return sd_r6; - - default: - break; - } - break; - case 4: /* CMD4: SEND_DSR */ switch (sd->state) { case sd_standby_state: @@ -2149,6 +2150,7 @@ static const SDProto sd_proto_sd = { [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, [52 ... 54] = sd_cmd_illegal, [58] = sd_cmd_illegal, From patchwork Mon May 30 19:38:03 2022 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: 12864913 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 D3D0AC433F5 for ; Mon, 30 May 2022 19:54:59 +0000 (UTC) Received: from localhost ([::1]:59854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlTe-0006sa-PQ for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFL-0000fp-7b; Mon, 30 May 2022 15:40:12 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:39935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFJ-000073-HS; Mon, 30 May 2022 15:40:10 -0400 Received: by mail-pj1-x102a.google.com with SMTP id q12-20020a17090a304c00b001e2d4fb0eb4so191036pjl.4; Mon, 30 May 2022 12:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8A7wws51gDKT5DGErSwXdU4YKfYnaGCZbjXp+wS8YIQ=; b=MZGoBShhGxr+wZbC4BpGDlm5bMWsgf0e4ZpSv+U19hoBQ6bvk7LRJbUv1rXsbV4OqK xgrte/ua/Qf4RFfuvA9C1tHtdD0gw4Bcc18y+tjMdQ6inxealTnE+w0bt0Y2cNDym+AG 6Fu6Tm5enKVG61vY78i3cGFqlBBhcDSQ7pX/1Mm+D0FIIJW/DEL29hMn+6av/ipCwmfq zl4Zkcvrvn9q/TcoUFsfikNjJjURDr9+cKvPc5DRPkpWwlvq5yF3LxbxoVWp4ui1qsaV a7lYvjtiZ3DkxFEUpZeqF6jI+9a1ebAJeTUVzyNakqCasiVM1EwmQfvmib3wz1fATOGM 7mkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8A7wws51gDKT5DGErSwXdU4YKfYnaGCZbjXp+wS8YIQ=; b=0BaSABB+qlLbE51vJS/+cKhRJB6GApHYIloSD9Df1mfKiYwmgijy56LDba1ke+t75X /AH8+3KJihHdUgbsk3jgNl6Iza1dt1UznZ5qu9QtQ+bUPKgX8vffyvt3FlXITHPXFqlc 4M4ueICGXicvWGB21TbbreFsP6nTOB2dzhE2XgGnSwZk1CE84olT9BeGATewo+rdml// aMkOTkOlg+h/j35bfiYe30knFVN6IZDBxV4HTtm/RgZanMj5oGzg40SasVoGQ91aKToa TF3Z6l9p7UGcpZamEtL0cW3NSBw15HrVNXmF1xoNirr/mOfzQ5g/lbVee6lYwM7EdAF0 AjSg== X-Gm-Message-State: AOAM532H+KcV63zrxFea3nZm3KpEwJZ1O193X2N1hPwqDCK7eGQZr4y0 RUBRjwkd0WpJtAKkOuVDsY3heKB4AqQ= X-Google-Smtp-Source: ABdhPJz7uAaQNkOo+4gMAvB5hLj5n5KEA97BPsLj8FHyo1r/TA7eXhoeM7TNrnnRCh3hsMxnFyAihA== X-Received: by 2002:a17:903:234c:b0:162:50f2:a850 with SMTP id c12-20020a170903234c00b0016250f2a850mr31628855plh.89.1653939607618; Mon, 30 May 2022 12:40:07 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id bk3-20020a056a02028300b003f5d7f0ad6asm8899350pgb.48.2022.05.30.12.40.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:07 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 12/25] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler Date: Mon, 30 May 2022 21:38:03 +0200 Message-Id: <20220530193816.45841-13-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Joel Stanley Signed-off-by: Joel Stanley Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater [PMD: Rebased] Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2fe05c5a3d..a9130155be 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1062,6 +1062,22 @@ 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->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_offset = 0; + + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1305,17 +1321,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ - if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - return sd_invalid_state_for_cmd(sd, req); - } - if (sd->state == sd_transfer_state) { - sd->state = sd_sendingdata_state; - sd->data_offset = 0; - return sd_r1; - } - break; - case 23: /* CMD23: SET_BLOCK_COUNT */ if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { return sd_invalid_state_for_cmd(sd, req); @@ -2152,6 +2157,7 @@ static const SDProto sd_proto_sd = { [2] = sd_cmd_ALL_SEND_CID, [3] = sd_cmd_SEND_RELATIVE_ADDR, [5] = sd_cmd_illegal, + [19] = sd_cmd_SEND_TUNING_BLOCK, [52 ... 54] = sd_cmd_illegal, [58] = sd_cmd_illegal, [59] = sd_cmd_illegal, From patchwork Mon May 30 19:38:04 2022 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: 12864910 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 C34FBC433EF for ; Mon, 30 May 2022 19:52:01 +0000 (UTC) Received: from localhost ([::1]:51246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlQm-00012O-Ql for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:52:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFU-0000sp-3B; Mon, 30 May 2022 15:40:23 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:39935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFR-000073-Ug; Mon, 30 May 2022 15:40:19 -0400 Received: by mail-pj1-x102a.google.com with SMTP id q12-20020a17090a304c00b001e2d4fb0eb4so191036pjl.4; Mon, 30 May 2022 12:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1/tjSehVrju13SeKU3/brCs7CeK81NyQsNDYvTYF194=; b=XeUS6LzmKdm6RCg3TBdJ50jab9Fj1lCRbShIjf7suxdqDuRuLJFxJLdE1q1Q3zQRin Q0p7PDBWYmv3rglt7ywKQacdPUDJHl0+XqbMTWAdBOnRT5Z+Er37FfbmU1iuM5ms50+U LDFAfVodoPvmV9aFZbSSAMZH59R+NkAUF+pc5mbN2cOR4kg2goppZ6galyzYHXpIODSL 5XHQaxXLYXb/XqHyBlT9XzcwlzoNgx14UIj29k/TKwkPi5zRq+GUEYQ8Nuc9EpVfEU3G 7pdXPyV+TgOzuXyzerX5kca5mrGqirOepwM6kWmBm+Iy5FJ3Xg5N2TOzdossef9WaNcT tD3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1/tjSehVrju13SeKU3/brCs7CeK81NyQsNDYvTYF194=; b=PY7VYMuRVBNkvW1miP9zQG/skGWHbjTG2MlxMbtVxvaGmOiX+78qOZYhCg8gP3sXQ2 1c3zono9+/cEyyC4MewDmnFlR+I44onHvoMcRQxnHbWyIqeXSu9w1Rn7N1LPqke7aC86 P7Q5efgmMAxM1QmOjHsXDXfg4OzdOKErErYepfMyIUb4kgDJnsegf31jQuJkNRNdc+pn CcoRRtpVhKyXu9dq6tja4I3baOwqK2N4dJy/JEAOTYSqzTVqWcbY7arWJyzy1I+Swzd6 s7DKvThen4crgrPekqP7JZvKWBJxnAsiMj916IMjkM19+pzJcC/yuBp0ZcJLr4SqSZDZ XI4Q== X-Gm-Message-State: AOAM530c/ZRk5FGEKwa6rOUaTWidFjCSMGEb8l+TxJuoiK3XfNVWljl2 XOGk4STUfIngdWbaWvLWo3u4Hme/JgU= X-Google-Smtp-Source: ABdhPJwLVvMsIzgxijS36RTcjazBZamT7M5hvMYu2ak8PHiFSnanhifV1lia71trQ6Nta9E5aWwZvw== X-Received: by 2002:a17:90b:1bcd:b0:1e2:c8da:7c29 with SMTP id oa13-20020a17090b1bcd00b001e2c8da7c29mr11537386pjb.4.1653939615919; Mon, 30 May 2022 12:40:15 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id q1-20020a170903204100b00163f35bd8f5sm1677040pla.289.2022.05.30.12.40.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 13/25] hw/sd: Add sd_cmd_SET_BLOCK_COUNT() handler Date: Mon, 30 May 2022 21:38:04 +0200 Message-Id: <20220530193816.45841-14-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a9130155be..b2f16dbb73 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1078,6 +1078,21 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) 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->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->multi_blk_cnt = req.arg; + + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca = 0x0000; @@ -1321,20 +1336,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 23: /* CMD23: SET_BLOCK_COUNT */ - if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { - return sd_invalid_state_for_cmd(sd, req); - } - switch (sd->state) { - case sd_transfer_state: - sd->multi_blk_cnt = req.arg; - return sd_r1; - - default: - break; - } - break; - /* Block write commands (Class 4) */ case 24: /* CMD24: WRITE_SINGLE_BLOCK */ case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ @@ -2158,6 +2159,7 @@ static const SDProto sd_proto_sd = { [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 May 30 19:38:05 2022 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: 12864909 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 9FC9FC433F5 for ; Mon, 30 May 2022 19:50:49 +0000 (UTC) Received: from localhost ([::1]:46474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlPc-00062k-NY for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:50:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFc-0000y7-53; Mon, 30 May 2022 15:40:31 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:35501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFa-0000FA-IN; Mon, 30 May 2022 15:40:27 -0400 Received: by mail-pg1-x533.google.com with SMTP id 129so6610682pgc.2; Mon, 30 May 2022 12:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MSS6iC8IugQOuzyUFIXMiVvOv251XPyXPK3tC9x4hyc=; b=H3qxdWwfvp1zQ5AW6Tg017juJR+zl9WAyu9URFuZ8EII4r963Bql+/ncYsMdER51cy OREd1RD6NTZZo9uZANgW96JwnLD6+5Qnr/VEias5IT8osibLSuhHilSbbDak3/OI2Pf2 ETEWby9Sc8u1YtvBNSTSTd1VTkV4lb+4E14pHqWdUHnhSCV1swPvpgq1kYahdP4Ho1i6 S+PHZuBcSOXM5kShRI94UDzJTRDKrWOeedxMBg0RbOZqBUL4Yt90oJZsUZcbmL8p4Z8a fVP4X8bIPlZyGAarugtP9oWmrCKaht9lyfiRdZOJh569cdzJwccfuX+4n6gaX2p5v5qK GV0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MSS6iC8IugQOuzyUFIXMiVvOv251XPyXPK3tC9x4hyc=; b=lpooyJkCJk7M2Kv6F844Cc31+ofKHfm8MJ42NzFC7UQVKwg5dOsR27dtC+zxfCoP26 HkVbirGCrhYhY0ECAjzsAtXKBRsat9V8NfEESfSVIlmm6rskSsfLrufmjTQhF5YCF55N 26jxOZkVj0oyE1IRlqb7nKguCptoDKE9TC2a3jO0tPrqYlxO2ixllbj76avvAQUMeHfR NalP1hWbecaN9BI22/ZsRDijJv5Qvldf9unDRkolnyDEKwUxr8viXr5l1sgefJkCZKlw uNxyddjN7+JNu6vEr0qju492CvD32acBiEfH497ecpbYh+GVLlHfJiskq5WTAy+r021r y/Jw== X-Gm-Message-State: AOAM533/09sxt8WtBAWKua5EGjZVQ7ow7jWkTF8aE3I5I2sUpWt4Iq8T 1m1sehJuaspJh93+SOZs++VYgt5lOVI= X-Google-Smtp-Source: ABdhPJz60kRxQuKzV0irftgtixR8zFDaCiQ5NndPu8QVcwtLj1VIJW6SBm72l3QxEXpJv+BM7cuRkQ== X-Received: by 2002:a05:6a00:1a91:b0:518:7bca:d095 with SMTP id e17-20020a056a001a9100b005187bcad095mr48085587pfv.13.1653939624542; Mon, 30 May 2022 12:40:24 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id w20-20020a170902a71400b0016232dbd01fsm9572052plq.292.2022.05.30.12.40.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 14/25] hw/sd: Basis for eMMC support Date: Mon, 30 May 2022 21:38:05 +0200 Message-Id: <20220530193816.45841-15-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Philippe Mathieu-Daudé The initial eMMC support from Vincent Palatin was largely reworked to match the current SD framework. Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- TODO: Do not inherit TYPE_SD_CARD, duplicate sd_class_init() --- hw/sd/sd.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/hw/sd/sd.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b2f16dbb73..8b178aa261 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2166,6 +2166,19 @@ static const SDProto sd_proto_sd = { }, }; +static const SDProto sd_proto_emmc = { + .name = "eMMC", + .cmd = { + [0] = sd_cmd_GO_IDLE_STATE, + [5] = sd_cmd_illegal, + [19] = sd_cmd_SEND_TUNING_BLOCK, + [41] = sd_cmd_illegal, + [52 ... 54] = sd_cmd_illegal, + [58] = sd_cmd_illegal, + [59] = sd_cmd_illegal, + }, +}; + static void sd_instance_init(Object *obj) { SDState *sd = SD_CARD(obj); @@ -2284,9 +2297,38 @@ static const TypeInfo sd_info = { .instance_finalize = sd_instance_finalize, }; +static void emmc_realize(DeviceState *dev, Error **errp) +{ + SDState *sd = SD_CARD(dev); + + if (sd->spec_version < SD_PHY_SPECv3_01_VERS) { + error_setg(errp, "Minimum spec for eMMC is v3.01"); + return; + } + + sd_realize(dev, errp); +} + +static void emmc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + SDCardClass *sc = SD_CARD_CLASS(klass); + + dc->desc = "eMMC"; + dc->realize = emmc_realize; + sc->proto = &sd_proto_emmc; +} + +static const TypeInfo emmc_info = { + .name = TYPE_EMMC, + .parent = TYPE_SD_CARD, + .class_init = emmc_class_init, + }; + static void sd_register_types(void) { type_register_static(&sd_info); + type_register_static(&emmc_info); } type_init(sd_register_types) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 0d94e1f346..e52436b7a5 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -93,6 +93,9 @@ typedef struct { #define TYPE_SD_CARD "sd-card" OBJECT_DECLARE_TYPE(SDState, SDCardClass, SD_CARD) +#define TYPE_EMMC "emmc" +DECLARE_INSTANCE_CHECKER(SDState, EMMC, TYPE_EMMC) + struct SDCardClass { /*< private >*/ DeviceClass parent_class; From patchwork Mon May 30 19:38:06 2022 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: 12864912 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 9B0A6C433F5 for ; Mon, 30 May 2022 19:53:33 +0000 (UTC) Received: from localhost ([::1]:55572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlSG-0003yy-Ol for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:53:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFk-00011g-Pi; Mon, 30 May 2022 15:40:37 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:33397) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFj-0000FX-A2; Mon, 30 May 2022 15:40:36 -0400 Received: by mail-pf1-x431.google.com with SMTP id w21so122228pfc.0; Mon, 30 May 2022 12:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3bD+/gL5DIK0X7iuBgZKzxQ+ir0BOqublJqqgaaEZNs=; b=a742GVZzEdMrm5XU/BPLymhdpnDz7nC2yRMcxM8fTBp0rmcaNLo660b5gDp/B4V2KU lsIv3aWwifKxQCnnGIN6Z5xpVniN7F/ulPfBgVZke7yXij1V+FvHpWSz0Hu3z0PeIOgF 3RLBvJ6f88l4pZtXn8F7PTL/LmssMKlGAIbbZEwlLLV/CBtAxAbsG79vGC8AKfYbKcv/ z6czFYa6BdB7anvrI46c17KZTC0+kZxo+p2p+PZpa18Y8RTYV3Qar7c5T4No0TYuPcWw cpS9oaApnY9l9eaQ8hW1ClnM0i6qqyzsFG23Xf8zY2LjJaK+RYTrWNQzME6426/h7E0N nlCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3bD+/gL5DIK0X7iuBgZKzxQ+ir0BOqublJqqgaaEZNs=; b=kle3TiY5l09ZEJm9iuO5NCppAaB9LSGpC9iiw9n4WBLYZr8J3lXZY8kviTBz0L0PwA 50w9z0XzSLqvj6Ww07JFTAN8YF4hK6qV0PJpIQZKSLTJt6qTj3c+pdwr4N4GgcrosPor 1F5sullnxVBaTRpOm26VP87D4nH3aAty8YKocFOnUct6EVDBDyFJObt4hXKcUL45kQgy opC4b2ZnFfFVhmVYsKCi/THDw8Kw63P5jKb6wJfpQQm7Pre9+f9AErx+aFDImtvmMAPp wqo5BKUv5nqrvdZJyh5C+GI8TOVf6trBiVeAIsUgGoMfKR4R0WM2DDuP6tPBKF33cpa/ ieQQ== X-Gm-Message-State: AOAM530t0d1GLwg+ULlJogfE0yJ38tn5Zc6Lechb2qjnIAhMgq8lkMO/ fjKawlPLjtk6xARn11WMWr36FIU8sb4= X-Google-Smtp-Source: ABdhPJzWiLC2gVEO9y/zScfs6/MhnDwkZw2MCRAstV88jLBLU8BqsTuSQCl3rPkrGLJmOvJW4eqyFg== X-Received: by 2002:a63:f913:0:b0:3fa:2b27:bb82 with SMTP id h19-20020a63f913000000b003fa2b27bb82mr36558323pgi.213.1653939633188; Mon, 30 May 2022 12:40:33 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v129-20020a626187000000b0050dc762814asm9276110pfb.36.2022.05.30.12.40.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 15/25] hw/sd: Add sd_emmc_cmd_SEND_OP_CMD() handler Date: Mon, 30 May 2022 21:38:06 +0200 Message-Id: <20220530193816.45841-16-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pf1-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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8b178aa261..538231dbab 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2166,10 +2166,17 @@ static const SDProto sd_proto_sd = { }, }; +static sd_rsp_type_t sd_emmc_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) +{ + sd->state = sd_ready_state; + return sd_r3; +} + static const SDProto sd_proto_emmc = { .name = "eMMC", .cmd = { [0] = sd_cmd_GO_IDLE_STATE, + [1] = sd_emmc_cmd_SEND_OP_CMD, [5] = sd_cmd_illegal, [19] = sd_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, From patchwork Mon May 30 19:38:07 2022 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: 12864917 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 24276C433F5 for ; Mon, 30 May 2022 19:58:32 +0000 (UTC) Received: from localhost ([::1]:41072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlX5-0004sT-AL for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:58:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlFt-00016j-0Q; Mon, 30 May 2022 15:40:46 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFr-0000GJ-B4; Mon, 30 May 2022 15:40:44 -0400 Received: by mail-pj1-x1036.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso196264pjl.3; Mon, 30 May 2022 12:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0cBhYgoYW3zeyEDvoShgTC1bQ+P+Lr18CMCPV7PbY6I=; b=dfzjvQNF+BJ9jF23fsxtvqb8TouysTJUVYXk2LuiacMI9Q5aBggqWXZW0s2Q1JA4iA sdj+UheYHFez2V5n7t+k4PW1+CIfqd8XK9yfLHfOEg7+afx72FKezl7pWRcQqdTxKY0o a0y7Y3G1IK4ayg8aXjrxkoEVitrIR70bGSax87c7XJ25LGNmJIYk8fPzJa/12XS8HaII nhLFpo09VrlmvGgXA1YL3oFN8lThk8LThAAXpuumMbAKr4tCNjed2rWyN+LnwH2Qlh/C Fo0rV06SXPfiodEogvTKlZzpKJ6xHviDLlhuh+X43iF38CyddPDpdpMZciql/HKGAArB WJkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0cBhYgoYW3zeyEDvoShgTC1bQ+P+Lr18CMCPV7PbY6I=; b=7kH+LpSHx194zfTeseuLp3N0L0Ufqu1AD9DaWJk3kmb06iNa0lgNMK8pTClHr/b2Xw eocYQvJKGNMFUPzp9PS59j4Wv17fix0Z4+AHdEwkwGXUe4hw2AStn72s7AvDWuEhuEKM MGYZQM6mZZj/9h3Y1q7zRcSpOkLBqPzGT3jeHJoswwIEx6adi0Uim73MrIJLJY9ZYKjv WGYPc7OHKoQXuUOAFqbnVW7F/D863r/Sbb3NVrPHWT3TU/WJRJw49aRbMcKkt2K5UP9+ vg2eSgVRz+TKaikQUwNNn0dx1hpquUGAPtv53TasGzIYHgliskTo9tqP5h+n7c21zJAf H4fA== X-Gm-Message-State: AOAM5313nMccY9D1KFa9LhUUIhZFOS23XRrwFFbgtefAgswoITxQK83v TrLwuw1utCAyxb7VQ9BowbQw8ZjNGoE= X-Google-Smtp-Source: ABdhPJxcEbcSKXh2QDUpmpnVv8nZqujjlTp1ibVnPiCkEsCMe6c/RFMi5CU77rK+ZlPLLKq0HNtvXA== X-Received: by 2002:a17:90a:df16:b0:1e3:1cd:6c6f with SMTP id gp22-20020a17090adf1600b001e301cd6c6fmr6147308pjb.10.1653939641573; Mon, 30 May 2022 12:40:41 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id n2-20020a63ee42000000b003f61c311e79sm4901832pgk.56.2022.05.30.12.40.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 16/25] hw/sd: Add sd_emmc_cmd_ALL_SEND_CID() handler Date: Mon, 30 May 2022 21:38:07 +0200 Message-Id: <20220530193816.45841-17-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 538231dbab..5e315f171c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2172,11 +2172,23 @@ static sd_rsp_type_t sd_emmc_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) return sd_r3; } +static sd_rsp_type_t sd_emmc_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) +{ + if (sd->state != sd_ready_state && sd->state != sd_idle_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_identification_state; + + return sd_r2_i; +} + static const SDProto sd_proto_emmc = { .name = "eMMC", .cmd = { [0] = sd_cmd_GO_IDLE_STATE, [1] = sd_emmc_cmd_SEND_OP_CMD, + [2] = sd_emmc_cmd_ALL_SEND_CID, [5] = sd_cmd_illegal, [19] = sd_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, From patchwork Mon May 30 19:38:08 2022 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: 12864918 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 31912C433F5 for ; Mon, 30 May 2022 19:59:43 +0000 (UTC) Received: from localhost ([::1]:43318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlYD-0006Os-9c for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:59:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlG1-0001CL-Mo; Mon, 30 May 2022 15:40:55 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:51937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlFz-0000H0-QN; Mon, 30 May 2022 15:40:53 -0400 Received: by mail-pj1-x1035.google.com with SMTP id cx11so3377665pjb.1; Mon, 30 May 2022 12:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IeIpypgJ4YsP/dCbKUVkwF0x+mKlRm0S64Ii1oPkA/s=; b=p4vBVKgA8V7P1wmOuCS9T0WiClGDgnqSRSrbdyvegMc1/v/HLtyMzfytf0l27DgoZK BAeeYWZCmdiRkNG+0f0mo1CY/MpzGKNrfNsV5N5OyYWwfE71pc8Fojnb1t9sIr+28Hzx HwWMmIZ9n7xZ53rmfuJV+fia6yegq+as9WUtJn2wmkRmBWkHyktzCJ6T0oduZxbh/0xM gpiy0bK9JgC2IA7gfQacuWkJUDplEahuWK2OibGYNi2L42tDjWKMeYVTou6gOFS9WH9n kZ8KzeL7NXdlT6gKbuMHe+M6FbwrMEa1gKifRXjQnXgqUMzm3I7XYnf1Viq+SNPmFT0F on+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IeIpypgJ4YsP/dCbKUVkwF0x+mKlRm0S64Ii1oPkA/s=; b=MWIyyxa91UZWv4oO1lgDEqlKfC4X8fjTSCEv9kQ5lwolCJaCaW+7YT8SEd1XCREUOn HvBCpfnZ5FZ8bwcrYhmaUXL5dXYGOyGVWR79U7069jv3eW3gGzxHYBMltwqnmRxUdWpd Eqf65Ii9c5R4buK/mUNGpNKm2nag3uzU4QdZY77uMcFM86p7q8wusVWvkhWDbjfbedRm IYOJn1HlQ/FuYbyjGv8OVaT6A+cCzRNJ+96AGgen4UVztB0s4YfRohgBMpbDCEa5sy5b 21bPQd29GlkkByHhNoONwhLvavTbtMHhzxUvBxmTP+DG0oNhM026o886ra9/nF/CwmsW 87bg== X-Gm-Message-State: AOAM531Zqd5hG/iQUn6NZyTPuiILRRdNJP8hExCfQYVNKTecyeY3nd2T juHzrlJzReGKgsPjnnXlHliEchf1HGM= X-Google-Smtp-Source: ABdhPJwaRFJaITyF0RHybTcZ2BpQmF9ptjOMGw5BC15W0kqZsO2Q0rZJNYhC0yY6M7N3q7T06Y+qhQ== X-Received: by 2002:a17:903:2304:b0:162:ed1:ed9c with SMTP id d4-20020a170903230400b001620ed1ed9cmr43212316plh.122.1653939650029; Mon, 30 May 2022 12:40:50 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id pf5-20020a17090b1d8500b001e2a36fb4aasm65644pjb.43.2022.05.30.12.40.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 17/25] hw/sd: Add sd_emmc_cmd_SEND_RELATIVE_ADDR() handler Date: Mon, 30 May 2022 21:38:08 +0200 Message-Id: <20220530193816.45841-18-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5e315f171c..100fe191a7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1048,6 +1048,25 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) return sd_r2_i; } +static void sd_emmc_set_rca(SDState *sd, uint16_t value) +{ + sd->rca = value; +} + +static sd_rsp_type_t sd_emmc_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_identification_state: + case sd_standby_state: + sd->state = sd_standby_state; + sd_emmc_set_rca(sd, req.arg >> 16); + return sd_r1; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) { switch (sd->state) { @@ -2189,6 +2208,7 @@ static const SDProto sd_proto_emmc = { [0] = sd_cmd_GO_IDLE_STATE, [1] = sd_emmc_cmd_SEND_OP_CMD, [2] = sd_emmc_cmd_ALL_SEND_CID, + [3] = sd_emmc_cmd_SEND_RELATIVE_ADDR, [5] = sd_cmd_illegal, [19] = sd_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, From patchwork Mon May 30 19:38:09 2022 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: 12864916 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 5E889C433F5 for ; Mon, 30 May 2022 19:57:05 +0000 (UTC) Received: from localhost ([::1]:36516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlVg-0001qc-DI for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:57:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGA-0001MR-H8; Mon, 30 May 2022 15:41:02 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:34553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlG8-0000Ho-Md; Mon, 30 May 2022 15:41:01 -0400 Received: by mail-pj1-x1029.google.com with SMTP id nn3-20020a17090b38c300b001e0e091cf03so247749pjb.1; Mon, 30 May 2022 12:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m+2eolDr3CGVIRnHJAwizCG0JzGaCJsy89c17GmqoJs=; b=b/Oxt7VbntZw5XhfAt705GbWEbHPEaJ1RXoHQS1eKTJnZ+GQLBFn/TNCyCk2t4SWyv obgLZpuW670usSRVvvNkN7Lt9uXYnCo/5cI3OXT3FgnSHnvu4MGrf3h3wXUZm5bwFJmo RRJY0mfJzGZDNo9DnxiSzQkPVP9ODLlAPG1HiJpj6VzKFeLzlsaKPMUCIL7/zL4/x5nw cJu6Lml61s/JFYlkMzHKRrQfOpYbPn0HrB7zpL97hWophVNX8B5aJTAECMSwEmeeLXOU 7Qes5hPjaY/eEE/AGaagZyHME+binYnrXdtzZY7X23QN6QlIjlQQyo82ERBj5rN9FlX2 rOlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m+2eolDr3CGVIRnHJAwizCG0JzGaCJsy89c17GmqoJs=; b=TxnhSOWJgwqVirhZc4YaM/87UvPL1zRCtBP3rF5PPfLYJUmHiOXtfuss/JlnJrmk1I lSzcY+c5vxKJUd+tm7WBEQuVlPYFkqQIs+0FwSeFo2C+ERn13Oi5hv8CPaAh0dXRtqg7 hQxTnlb5m4wzDOb8uEpKAdRQ+n/axkuSSDGeTZN7zJHp1NXZt7Mo+F/DhHH/tQgdArSc vZtre69ZB3UIB4BALK2O1Q1I1I8wCUt/raqyOvg01HND4IwFw2mtIVuBGjrT33hqjHIJ LAK88UmCquIy+X/Tuj3Dmn6hFfrv9mHBdHj1toLAGlQztHhiRIbFSjo4GMRLqyD91QGw ln5Q== X-Gm-Message-State: AOAM531wyuTF3dzCARldUEyN8/RaCHe1qx6QEQo1mowedsB7nowuvbb/ 7Wz0KWOv96liVdRJY1LO7DQNkv1sLb0= X-Google-Smtp-Source: ABdhPJwPLhm24pk2hKUiQP/lmHkDy03W1XFocsBH32yV3tIWRn0lF2ibhFrqkM6rX7e3t0T69ccqwQ== X-Received: by 2002:a17:90a:ba0b:b0:1e0:97b4:e0ad with SMTP id s11-20020a17090aba0b00b001e097b4e0admr24667261pjr.19.1653939658462; Mon, 30 May 2022 12:40:58 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id q44-20020a17090a17af00b001cd4989ff41sm86745pja.8.2022.05.30.12.40.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:40:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 18/25] hw/sd: Add sd_emmc_cmd_APP_CMD() handler Date: Mon, 30 May 2022 21:38:09 +0200 Message-Id: <20220530193816.45841-19-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 100fe191a7..90da24ad2d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2202,6 +2202,11 @@ static sd_rsp_type_t sd_emmc_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) return sd_r2_i; } +static sd_rsp_type_t sd_emmc_cmd_APP_CMD(SDState *sd, SDRequest req) +{ + return sd_r0; +} + static const SDProto sd_proto_emmc = { .name = "eMMC", .cmd = { @@ -2213,6 +2218,7 @@ static const SDProto sd_proto_emmc = { [19] = sd_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, [52 ... 54] = sd_cmd_illegal, + [55] = sd_emmc_cmd_APP_CMD, [58] = sd_cmd_illegal, [59] = sd_cmd_illegal, }, From patchwork Mon May 30 19:38:10 2022 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: 12864919 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 635E0C433EF for ; Mon, 30 May 2022 20:00:15 +0000 (UTC) Received: from localhost ([::1]:44152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlYk-0006yR-AJ for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:00:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGH-0001Zl-IT; Mon, 30 May 2022 15:41:09 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlGF-0000GJ-T7; Mon, 30 May 2022 15:41:09 -0400 Received: by mail-pj1-x1036.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso196264pjl.3; Mon, 30 May 2022 12:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xCLgBMbpBxR8PGqqnVdVF4Mxh0waVagEBbV26nroY/U=; b=b/JEUHzpBRbZcmoydkZxRH/ZqEVZuph945zxIqHZpR4j8i8uaVKMc2KlznNRHU/yLa 1gMg+oVi4003io+wiXTJU4kwiT//7v8sd7QCuSL+hrmgMb9QF1/O/orOY0xkBYgb8fXP 4nR0VT1xUgVhq5mRDh4rtkrJO0Z9+AhD0vuYUlYX5ploWem1c0DbhgUld6nlaYMUTzA5 yP/aqIv0NMi6rHDu0faqEs5s4YCY2sk2phm9utDfZ9jPWwREFzkVyIy7revpPQheNhWi AiGz+3hLHGNqmK89FPGQPyYjxOdRABwaztH6ezEsYnIcjtBPpAElB9DigLOeDrfYF013 STTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xCLgBMbpBxR8PGqqnVdVF4Mxh0waVagEBbV26nroY/U=; b=Vzb2KZU7p2nCAwB3HvVRwP+3XbVajSVLeMOOuO7gdJhQdvhdbLj0QoPHu3ESEJ81Zm dZDx6K3LzXcz+s5Z0IAs6l5GLUqurxbClZtsSePW5EPFhMLMEn/Jeq5SGmuxJviw1WHV jzc0NOJDybRgUMpeSRo0/u+8P8i8EAplHXLmL2mMpXdy6yCX03OO4ZkwEH5Bp0HzxGAV chXIgDS13n5/vlxYrVcnk/Mffq3xnW0GfNE4NPcDMVCgRHzd07h/CwhXj+0iN6JGKBLF jqOdKui7MxvctRB5oe2AAIdCTphjKPGz5/ou2vLX7CSUQ3ncFTHNooARk4iAjZ3Lkiy/ 4lJw== X-Gm-Message-State: AOAM532NYYQYh1Ls+F85BR/hB4LikfeFsbGyUi62Y2NlfssquT/OfekR gsDojOaZ6BvC3XUbyN8/z9mcSt32sm0= X-Google-Smtp-Source: ABdhPJwMj4mznrT+bSqO6esQg1xx07zuPKncJcDCk6BAQJLiiR5iB0mz5mErQjd+f0tySweMpNdwRw== X-Received: by 2002:a17:903:189:b0:163:56c3:8506 with SMTP id z9-20020a170903018900b0016356c38506mr27890444plg.70.1653939666747; Mon, 30 May 2022 12:41:06 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id q8-20020a17090a7a8800b001e2cbb55b45sm57715pjf.53.2022.05.30.12.41.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 19/25] hw/sd: add sd_emmc_cmd_SEND_TUNING_BLOCK() handler Date: Mon, 30 May 2022 21:38:10 +0200 Message-Id: <20220530193816.45841-20-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 90da24ad2d..d38ee5094d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2207,6 +2207,17 @@ static sd_rsp_type_t sd_emmc_cmd_APP_CMD(SDState *sd, SDRequest req) return sd_r0; } +static sd_rsp_type_t sd_emmc_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_offset = 0; + return sd_r1; +} + static const SDProto sd_proto_emmc = { .name = "eMMC", .cmd = { @@ -2216,6 +2227,7 @@ static const SDProto sd_proto_emmc = { [3] = sd_emmc_cmd_SEND_RELATIVE_ADDR, [5] = sd_cmd_illegal, [19] = sd_cmd_SEND_TUNING_BLOCK, + [21] = sd_emmc_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, [52 ... 54] = sd_cmd_illegal, [55] = sd_emmc_cmd_APP_CMD, From patchwork Mon May 30 19:38:11 2022 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: 12864921 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 80B88C433EF for ; Mon, 30 May 2022 20:03:07 +0000 (UTC) Received: from localhost ([::1]:50600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlbW-00039Q-CG for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:03:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGR-00025b-24; Mon, 30 May 2022 15:41:19 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:44631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlGP-0000Nw-BZ; Mon, 30 May 2022 15:41:18 -0400 Received: by mail-pj1-x102f.google.com with SMTP id gc3-20020a17090b310300b001e33092c737so183180pjb.3; Mon, 30 May 2022 12:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3kaUIlgB+HCi67jzp3tJaQRHe02uDC7eaPM7cAd48kU=; b=TSfqkfNgrl71Ke5XRpV6DfPNJQ4ZUcdHSBuUXKfvK9FFiBDc/DcIgGJbtuekc4AVD0 st3bqL36JjQ4ivX9goFafevN/9Rqnw0wMVftrNnST1uGjRt1+yAzDszO8ZqnYJaGMUCU uSoXGHUNdNiWqWbrvLluB0VPPaac4zm8VPZiOdMoT/T22XOkODNQoVvkIAnI4iLaoYuQ U/FkTmUYc/iiOe+nxEiH+2Rdm78gGwVQIDFWpAzHJYNGPFwG71c3ZPmfjWkPMFxrYW8I N7Qld23FlVgbzpisUxpZBNnGXVUTF/HpnLzUNHXi8vKaLJcw8VcYnGtTsVl7+Hkh2NQ0 idKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3kaUIlgB+HCi67jzp3tJaQRHe02uDC7eaPM7cAd48kU=; b=HKWdKex0fpXjHsXMmx0LYrzh6r95qDibOiU7YKKZE9ZJjoQVG/HuPuLvwWyDxjbDX8 2PJlQs9g7ZLwZyG957cWp57YnR/c6XM8F0vfxc2HcQvw5qiU3W9CZSrOtzdjksUVUJma j/I39OGAOaxf5bl3128ALSWia+io1qpZDJK1RSfmYktxC8IARYrpGry7zOIXHwURCZzO N1UzGsXBon10vmuj/U13TPR/N+oYBz6EMSgFp5NQyvf0bqCvl4o5vBTp2rjyXePmXi2z R1Zik4MMTUiWM6NOi3kl/jiUMsEtLPhDtcCHPWi0B+mPcHJSHKxyTohBtO9FXzOZfP2h PX1Q== X-Gm-Message-State: AOAM5304Z3aUSr0Irw36kAnOoNlrfixtlvO//qEjezo+2T9oDny+ZI4q /yYEbVGhm9iANBUoK8AGb1rihtKM2IM= X-Google-Smtp-Source: ABdhPJwmuh72H4zElqNgKxSSvgZc6V8P+EikBg496rH+bOFqYrCytmIUBXmjeRPKu4R9K5GLOorZVQ== X-Received: by 2002:a17:902:b402:b0:162:29a3:9331 with SMTP id x2-20020a170902b40200b0016229a39331mr39055744plr.59.1653939675394; Mon, 30 May 2022 12:41:15 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id c14-20020a17090a674e00b001e3290cc2c1sm69537pjm.34.2022.05.30.12.41.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , "Edgar E . Iglesias" Subject: [PATCH v2 20/25] hw/sd: Add CMD21 tuning sequence Date: Mon, 30 May 2022 21:38:11 +0200 Message-Id: <20220530193816.45841-21-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Sai Pavan Boddu MMC cards support different tuning sequence for entering HS200 mode. Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias [ clg: - ported on QEMU 7.0 ] Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d38ee5094d..672af1e839 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2012,6 +2012,30 @@ static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE] = { 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde, }; +#define EXCSD_BUS_WIDTH_OFFSET 183 +#define BUS_WIDTH_8_MASK 0x4 +#define BUS_WIDTH_4_MASK 0x2 +#define MMC_TUNING_BLOCK_SIZE 128 + +static const uint8_t mmc_tuning_block_pattern[128] = { + 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc, + 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff, + 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff, + 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd, + 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, + 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff, + 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff, + 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, + 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, + 0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, + 0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, + 0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, + 0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, + 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, +}; + uint8_t sd_read_byte(SDState *sd) { /* TODO: Append CRCs */ @@ -2098,6 +2122,21 @@ uint8_t sd_read_byte(SDState *sd) ret = sd_tuning_block_pattern[sd->data_offset++]; break; + case 21: /* CMD21: SEND_TUNING_BLOCK (MMC) */ + if (sd->data_offset >= MMC_TUNING_BLOCK_SIZE - 1) { + sd->state = sd_transfer_state; + } + if (sd->ext_csd[EXCSD_BUS_WIDTH_OFFSET] & BUS_WIDTH_8_MASK) { + ret = mmc_tuning_block_pattern[sd->data_offset++]; + } else { + /* Return LSB Nibbles of two byte from the 8bit tuning block + * for 4bit mode + */ + ret = mmc_tuning_block_pattern[sd->data_offset++] & 0x0F; + ret |= (mmc_tuning_block_pattern[sd->data_offset++] & 0x0F) << 4; + } + break; + case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ ret = sd->data[sd->data_offset ++]; From patchwork Mon May 30 19:38:12 2022 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: 12864920 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 6D5A8C433EF for ; Mon, 30 May 2022 20:01:57 +0000 (UTC) Received: from localhost ([::1]:47664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlaO-00011o-E3 for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:01:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGa-0002S8-QP; Mon, 30 May 2022 15:41:28 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlGZ-0000Pv-4h; Mon, 30 May 2022 15:41:28 -0400 Received: by mail-pl1-x62d.google.com with SMTP id b5so11033794plx.10; Mon, 30 May 2022 12:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9ttuQlAhLvhQoRUw1TZJLfp+t9TBlRFis3dat+1QSh8=; b=I9B14NU45VohPfR5NnNMws5CDk5zFs01LYDtv3To3lMUB7snFP6JiKBFu6mvtOhXes BVse0+BiRSHY+UDMZh6tgOKub8CZOBowRVasLydoyrScLk9llB10TF7AJ8qUiDwZ+5Dg mnSWgNrDjLDQg1bE/KdbrzUaVyPmRBtf5qpkQz15+xe+NkvhvSAaXv0+WSRh0AJTSQJp h1WkSxUouZjLBWmgbCTadoM6tgOMVkGN4s0cuEGmG52pV9xZgh9RuqFaVzWk1CRApKIc bsY8SCh034sQG3FL6szCOjXOo+t/DWkGJ5m/vSICfSRVZ3xHITnylm5uhYa87ALC6epT UEyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9ttuQlAhLvhQoRUw1TZJLfp+t9TBlRFis3dat+1QSh8=; b=wE0xz+QX4XzKlBgDPIaNYqFjeO2QKrwXEMYOg98ChQTfPNt5BV990Fn2IuFzyHuSpR yM+KtiEBA5YnOy4twsqcliGO5MMBe9Y56+z12pb8BR8vZMeQi7CO2iSaU4kYp9R95m0Y Kk8SLgmpqVoxgnH9nfavDU/vZyStWaTUp/ARW7vZhSHUOWDUWYrmRmv1I/89cwUZWPjN teoBwVVXnwIrqht2bQW3XCQ27ET/SsUjulytMWfvoDGv26wNuMzZtH+T8lEQKzcNJZcc emaV+W+d3OorT/uH6xHy68BWXbTDOwlnEOPc3CRy0CZKVUPI6S1jBkX4wNQtgVOAdRME ybZA== X-Gm-Message-State: AOAM530oKyqEX9uNntTs8E/xzA7MskHApweYijtNJ5iLrfult1W+n98L Cm/44GD/d+zkYnMJxobSevVQaLoSXYg= X-Google-Smtp-Source: ABdhPJyFkjYbTyf8UbKyTv32ZMoW1EQ/Bth5TAFTlEASRUlSKnSQdcbcg85yP0eXhe6+sxno+nCI7g== X-Received: by 2002:a17:90a:d515:b0:1e3:1d65:e06b with SMTP id t21-20020a17090ad51500b001e31d65e06bmr3477019pju.24.1653939684356; Mon, 30 May 2022 12:41:24 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id y63-20020a638a42000000b003fadfd7be5asm8771965pgd.18.2022.05.30.12.41.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu , "Edgar E . Iglesias" Subject: [PATCH v2 21/25] hw/sd: Add mmc switch function support Date: Mon, 30 May 2022 21:38:12 +0200 Message-Id: <20220530193816.45841-22-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Sai Pavan Boddu switch operation in mmc cards, updated the ext_csd register to request changes in card operations. Here we implement similar sequence but requests are mostly dummy and make no change. Implement SWITCH_ERROR if the write operation offset goes beyond length of ext_csd. Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias [ clg: - ported on SDProto framework ] Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 672af1e839..907d4f5760 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -476,6 +476,7 @@ static void sd_set_rca(SDState *sd) FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) +FIELD(CSR, SWITCH_ERROR, 7, 1) FIELD(CSR, READY_FOR_DATA, 8, 1) FIELD(CSR, CURRENT_STATE, 9, 4) FIELD(CSR, ERASE_RESET, 13, 1) @@ -873,6 +874,43 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) return ret; } +enum { + MMC_CMD6_ACCESS_COMMAND_SET = 0, + MMC_CMD6_ACCESS_SET_BITS, + MMC_CMD6_ACCESS_CLEAR_BITS, + MMC_CMD6_ACCESS_WRITE_BYTE, +}; + +static void mmc_function_switch(SDState *sd, uint32_t arg) +{ + uint32_t access = extract32(arg, 24, 2); + uint32_t index = extract32(arg, 16, 8); + uint32_t value = extract32(arg, 8, 8); + uint8_t b = sd->ext_csd[index]; + + switch (access) { + case MMC_CMD6_ACCESS_COMMAND_SET: + qemu_log_mask(LOG_UNIMP, "MMC Command set switching not supported\n"); + return; + case MMC_CMD6_ACCESS_SET_BITS: + b |= value; + break; + case MMC_CMD6_ACCESS_CLEAR_BITS: + b &= ~value; + break; + case MMC_CMD6_ACCESS_WRITE_BYTE: + b = value; + break; + } + + if (index >= 192) { + sd->card_status |= R_CSR_SWITCH_ERROR_MASK; + return; + } + + sd->ext_csd[index] = b; +} + static void sd_function_switch(SDState *sd, uint32_t arg) { int i, mode, new_func; @@ -2257,6 +2295,19 @@ static sd_rsp_type_t sd_emmc_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) return sd_r1; } +static sd_rsp_type_t sd_emmc_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_transfer_state: + sd->state = sd_programming_state; + mmc_function_switch(sd, req.arg); + sd->state = sd_transfer_state; + return sd_r1b; + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + static const SDProto sd_proto_emmc = { .name = "eMMC", .cmd = { @@ -2265,6 +2316,7 @@ static const SDProto sd_proto_emmc = { [2] = sd_emmc_cmd_ALL_SEND_CID, [3] = sd_emmc_cmd_SEND_RELATIVE_ADDR, [5] = sd_cmd_illegal, + [6] = sd_emmc_cmd_SWITCH_FUNCTION, [19] = sd_cmd_SEND_TUNING_BLOCK, [21] = sd_emmc_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, From patchwork Mon May 30 19:38:13 2022 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: 12864923 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 93978C433EF for ; Mon, 30 May 2022 20:05:34 +0000 (UTC) Received: from localhost ([::1]:56082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvldt-0006tB-8B for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGi-0002o5-8R; Mon, 30 May 2022 15:41:36 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlGg-0000Pv-1E; Mon, 30 May 2022 15:41:35 -0400 Received: by mail-pl1-x62d.google.com with SMTP id b5so11033794plx.10; Mon, 30 May 2022 12:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cay/+i/hTNFY+iYn24yik69HI3xJpqL9BHNLf7smU+Y=; b=Qyi5p5LDX2+Zv3PvQa0dMi8eqhc4mR2+oiWEcRgIukGTC5aI8jbyfJBQtXt228sF0p WmeHx4bNkPI93XcU69l88XwGOjKaEs2iiylHI44RDHYdJc1dnjsj9EoNx5WZ/Q+d4DmE DeAMJ1uqWnDnVCwNWvw//Rr1wjmJxr1XroY2g7LG6uDnXv5TWk1JF0NmP9543GFL1nZy 2QBEWVbVDEUq113mBDR0sf6Bpxr46jFWOYnrU5f1g8UoPKwD+M2VHZfgwQJU+hwuNLVP t2M9fIlbqsojJPaq3CnoTl51tCB4xWVUvVecuA/lD2srZUuVowB9syb8AY/v7q8Cb+I2 oylw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cay/+i/hTNFY+iYn24yik69HI3xJpqL9BHNLf7smU+Y=; b=KoOdjNROFeZDHwF4YzcmgFXsAyihw7lIRixviQW+d8BU81Xx3h726enWE1vC5DO7o3 DtfoYhxSQ0uwkt+ncIwXtoxoeH7p6hSllZ2kI9V3jJpSK/jtRbhT98alxG983gb1OjG0 68g0nllXi98X4Yrt39aDr6SC0UnaFwBmUJpy68ozegeS7D4Yj80h4AnzOaMErUvqu4sx 9ahSb3UjmE8KB+8P7ESmjCrjdRF3+lVNwacF5zfrv66df1SL9f1Sgrd2ZN21esu8jNNT ZRMI3020AW/1ieAYL1T8YuBC8zsKKuPVN7xQC+89yiIGMfgsMyEDv0uvpQLzaiuv6aTf hoFg== X-Gm-Message-State: AOAM5320dudwuf5n0rwPUTnGlEbjVmPeCWEb4fisWHtmfkv946CzHMNI oeXgCRuLgtbSUuEXYAJVO4qiHpcL8D8= X-Google-Smtp-Source: ABdhPJwd2tshJDuflauFRHiMppIfDwbR93NctE4oGG3XqACwzoiG59CRS9wfrcScqarApCxQjCUJOg== X-Received: by 2002:a17:90b:188:b0:1e3:1feb:edb2 with SMTP id t8-20020a17090b018800b001e31febedb2mr3168344pjs.195.1653939692681; Mon, 30 May 2022 12:41:32 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id d14-20020a170902cece00b001620db30cd6sm9699273plg.201.2022.05.30.12.41.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 22/25] hw/sd: Add sd_emmc_cmd_SEND_EXT_CSD() handler Date: Mon, 30 May 2022 21:38:13 +0200 Message-Id: <20220530193816.45841-23-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Cédric Le Goater The parameters mimick a real 4GB eMMC, but it can be set to various sizes. Initially from Vincent Palatin Signed-off-by: Cédric Le Goater [PMD: Remove CMD8 (SEND_EXT_CSD) case in sd_read_byte()] Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 101 ++++++++++++++++++++++++++++++++++++++++- hw/sd/sdmmc-internal.h | 97 +++++++++++++++++++++++++++++++++++++++ include/hw/sd/sd.h | 1 + 3 files changed, 198 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 907d4f5760..6722003cda 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -142,6 +142,7 @@ struct SDState { uint64_t data_start; uint32_t data_offset; uint8_t data[512]; + uint8_t ext_csd[512]; qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; @@ -408,8 +409,85 @@ static const uint8_t sd_csd_rw_mask[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, }; +static void mmc_set_ext_csd(SDState *sd, uint64_t size) +{ + uint32_t sectcount = size >> HWBLOCK_SHIFT; + + memset(sd->ext_csd, 0, sizeof(sd->ext_csd)); + + sd->ext_csd[EXT_CSD_S_CMD_SET] = 0x1; /* supported command sets */ + sd->ext_csd[EXT_CSD_HPI_FEATURES] = 0x3; /* HPI features */ + sd->ext_csd[EXT_CSD_BKOPS_SUPPORT] = 0x1; /* Background operations */ + sd->ext_csd[241] = 0xA; /* 1st initialization time after partitioning */ + sd->ext_csd[EXT_CSD_TRIM_MULT] = 0x1; /* Trim multiplier */ + sd->ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] = 0x15; /* Secure feature */ + sd->ext_csd[EXT_CSD_SEC_ERASE_MULT] = 0x96; /* Secure erase support */ + sd->ext_csd[EXT_CSD_SEC_TRIM_MULT] = 0x96; /* Secure TRIM multiplier */ + sd->ext_csd[EXT_CSD_BOOT_INFO] = 0x7; /* Boot information */ + sd->ext_csd[EXT_CSD_BOOT_MULT] = 0x8; /* Boot partition size. 128KB unit */ + sd->ext_csd[EXT_CSD_ACC_SIZE] = 0x6; /* Access size */ + sd->ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] = 0x4; /* HC Erase unit size */ + sd->ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] = 0x1; /* HC erase timeout */ + sd->ext_csd[EXT_CSD_REL_WR_SEC_C] = 0x1; /* Reliable write sector count */ + sd->ext_csd[EXT_CSD_HC_WP_GRP_SIZE] = 0x4; /* HC write protect group size */ + sd->ext_csd[EXT_CSD_S_C_VCC] = 0x8; /* Sleep current VCC */ + sd->ext_csd[EXT_CSD_S_C_VCCQ] = 0x7; /* Sleep current VCCQ */ + sd->ext_csd[EXT_CSD_S_A_TIMEOUT] = 0x11; /* Sleep/Awake timeout */ + sd->ext_csd[215] = (sectcount >> 24) & 0xff; /* Sector count */ + sd->ext_csd[214] = (sectcount >> 16) & 0xff; /* ... */ + sd->ext_csd[213] = (sectcount >> 8) & 0xff; /* ... */ + sd->ext_csd[EXT_CSD_SEC_CNT] = (sectcount & 0xff); /* ... */ + sd->ext_csd[210] = 0xa; /* Min write perf for 8bit@52Mhz */ + sd->ext_csd[209] = 0xa; /* Min read perf for 8bit@52Mhz */ + sd->ext_csd[208] = 0xa; /* Min write perf for 4bit@52Mhz */ + sd->ext_csd[207] = 0xa; /* Min read perf for 4bit@52Mhz */ + sd->ext_csd[206] = 0xa; /* Min write perf for 4bit@26Mhz */ + sd->ext_csd[205] = 0xa; /* Min read perf for 4bit@26Mhz */ + sd->ext_csd[EXT_CSD_PART_SWITCH_TIME] = 0x1; + sd->ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] = 0x1; + sd->ext_csd[EXT_CSD_CARD_TYPE] = 0x7; + sd->ext_csd[EXT_CSD_STRUCTURE] = 0x2; + sd->ext_csd[EXT_CSD_REV] = 0x5; + sd->ext_csd[EXT_CSD_RPMB_MULT] = 0x1; /* RPMB size */ + sd->ext_csd[EXT_CSD_PARTITION_SUPPORT] = 0x3; + sd->ext_csd[159] = 0x00; /* Max enhanced area size */ + sd->ext_csd[158] = 0x00; /* ... */ + sd->ext_csd[157] = 0xEC; /* ... */ +} + +static void sd_emmc_set_csd(SDState *sd, uint64_t size) +{ + sd->csd[0] = 0xd0; + sd->csd[1] = 0x0f; + sd->csd[2] = 0x00; + sd->csd[3] = 0x32; + sd->csd[4] = 0x0f; + if (size <= 2 * GiB) { + /* use 1k blocks */ + uint32_t csize1k = (size >> (CMULT_SHIFT + 10)) - 1; + sd->csd[5] = 0x5a; + sd->csd[6] = 0x80 | ((csize1k >> 10) & 0xf); + sd->csd[7] = (csize1k >> 2) & 0xff; + } else { /* >= 2GB : size stored in ext CSD, block addressing */ + sd->csd[5] = 0x59; + sd->csd[6] = 0x8f; + sd->csd[7] = 0xff; + sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); + } + sd->csd[8] = 0xff; + sd->csd[9] = 0xff; + sd->csd[10] = 0xf7; + sd->csd[11] = 0xfe; + sd->csd[12] = 0x49; + sd->csd[13] = 0x10; + sd->csd[14] = 0x00; + sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; + mmc_set_ext_csd(sd, size); +} + static void sd_set_csd(SDState *sd, uint64_t size) { + SDCardClass *sc = SD_CARD_GET_CLASS(sd); int hwblock_shift = HWBLOCK_SHIFT; uint32_t csize; uint32_t sectsize = (1 << (SECTOR_SHIFT + 1)) - 1; @@ -421,7 +499,9 @@ static void sd_set_csd(SDState *sd, uint64_t size) } csize = (size >> (CMULT_SHIFT + hwblock_shift)) - 1; - if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */ + if (sc->set_csd) { + sc->set_csd(sd, size); + } else if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */ sd->csd[0] = 0x00; /* CSD structure */ sd->csd[1] = 0x26; /* Data read access-time-1 */ sd->csd[2] = 0x00; /* Data read access-time-2 */ @@ -2279,6 +2359,23 @@ static sd_rsp_type_t sd_emmc_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) return sd_r2_i; } +static sd_rsp_type_t sd_emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) +{ + uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg; + + switch (sd->state) { + case sd_transfer_state: + /* MMC : Sends the EXT_CSD register as a Block of data */ + sd->state = sd_sendingdata_state; + memcpy(sd->data, sd->ext_csd, sizeof(sd->ext_csd)); + sd->data_start = addr; + sd->data_offset = 0; + return sd_r1; + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + static sd_rsp_type_t sd_emmc_cmd_APP_CMD(SDState *sd, SDRequest req) { return sd_r0; @@ -2317,6 +2414,7 @@ static const SDProto sd_proto_emmc = { [3] = sd_emmc_cmd_SEND_RELATIVE_ADDR, [5] = sd_cmd_illegal, [6] = sd_emmc_cmd_SWITCH_FUNCTION, + [8] = sd_emmc_cmd_SEND_EXT_CSD, [19] = sd_cmd_SEND_TUNING_BLOCK, [21] = sd_emmc_cmd_SEND_TUNING_BLOCK, [41] = sd_cmd_illegal, @@ -2465,6 +2563,7 @@ static void emmc_class_init(ObjectClass *klass, void *data) dc->desc = "eMMC"; dc->realize = emmc_realize; sc->proto = &sd_proto_emmc; + sc->set_csd = sd_emmc_set_csd; } static const TypeInfo emmc_info = { diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h index d8bf17d204..2b98f117cd 100644 --- a/hw/sd/sdmmc-internal.h +++ b/hw/sd/sdmmc-internal.h @@ -37,4 +37,101 @@ const char *sd_cmd_name(uint8_t cmd); */ const char *sd_acmd_name(uint8_t cmd); +/* + * EXT_CSD fields + */ + +#define EXT_CSD_CMDQ_MODE_EN 15 /* R/W */ +#define EXT_CSD_FLUSH_CACHE 32 /* W */ +#define EXT_CSD_CACHE_CTRL 33 /* R/W */ +#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35 /* RO */ +#define EXT_CSD_PACKED_CMD_STATUS 36 /* RO */ +#define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO, 2 bytes */ +#define EXT_CSD_EXP_EVENTS_CTRL 56 /* R/W, 2 bytes */ +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ +#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ +#define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ +#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ +#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ +#define EXT_CSD_HPI_MGMT 161 /* R/W */ +#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ +#define EXT_CSD_BKOPS_EN 163 /* R/W */ +#define EXT_CSD_BKOPS_START 164 /* W */ +#define EXT_CSD_SANITIZE_START 165 /* W */ +#define EXT_CSD_WR_REL_PARAM 166 /* RO */ +#define EXT_CSD_RPMB_MULT 168 /* RO */ +#define EXT_CSD_FW_CONFIG 169 /* R/W */ +#define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_PART_CONFIG 179 /* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ +#define EXT_CSD_BUS_WIDTH 183 /* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184 /* RO */ +#define EXT_CSD_HS_TIMING 185 /* R/W */ +#define EXT_CSD_POWER_CLASS 187 /* R/W */ +#define EXT_CSD_REV 192 /* RO */ +#define EXT_CSD_STRUCTURE 194 /* RO */ +#define EXT_CSD_CARD_TYPE 196 /* RO */ +#define EXT_CSD_DRIVER_STRENGTH 197 /* RO */ +#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198 /* RO */ +#define EXT_CSD_PART_SWITCH_TIME 199 /* RO */ +#define EXT_CSD_PWR_CL_52_195 200 /* RO */ +#define EXT_CSD_PWR_CL_26_195 201 /* RO */ +#define EXT_CSD_PWR_CL_52_360 202 /* RO */ +#define EXT_CSD_PWR_CL_26_360 203 /* RO */ +#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217 /* RO */ +#define EXT_CSD_S_C_VCCQ 219 /* RO */ +#define EXT_CSD_S_C_VCC 220 /* RO */ +#define EXT_CSD_REL_WR_SEC_C 222 /* RO */ +#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ +#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ +#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ +#define EXT_CSD_ACC_SIZE 225 /* RO */ +#define EXT_CSD_BOOT_MULT 226 /* RO */ +#define EXT_CSD_BOOT_INFO 228 /* RO */ +#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */ +#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ +#define EXT_CSD_TRIM_MULT 232 /* RO */ +#define EXT_CSD_PWR_CL_200_195 236 /* RO */ +#define EXT_CSD_PWR_CL_200_360 237 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_195 238 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */ +#define EXT_CSD_BKOPS_STATUS 246 /* RO */ +#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */ +#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ +#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ +#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */ +#define EXT_CSD_PRE_EOL_INFO 267 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269 /* RO */ +#define EXT_CSD_CMDQ_DEPTH 307 /* RO */ +#define EXT_CSD_CMDQ_SUPPORT 308 /* RO */ +#define EXT_CSD_SUPPORTED_MODE 493 /* RO */ +#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ +#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ +#define EXT_CSD_MAX_PACKED_WRITES 500 /* RO */ +#define EXT_CSD_MAX_PACKED_READS 501 /* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ +#define EXT_CSD_HPI_FEATURES 503 /* RO */ +#define EXT_CSD_S_CMD_SET 504 /* RO */ + +/* + * EXT_CSD field definitions + */ + +#define EXT_CSD_WR_REL_PARAM_EN (1 << 2) +#define EXT_CSD_WR_REL_PARAM_EN_RPMB_REL_WR (1 << 4) + +#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) +#define EXT_CSD_PART_CONFIG_ACC_DEFAULT (0x0) +#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) + +#define EXT_CSD_PART_CONFIG_EN_MASK (0x7 << 3) +#define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3) +#define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) + #endif diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index e52436b7a5..8a0f2e75da 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -129,6 +129,7 @@ struct SDCardClass { bool (*get_readonly)(SDState *sd); const struct SDProto *proto; + void (*set_csd)(SDState *sd, uint64_t size); }; #define TYPE_SD_BUS "sd-bus" From patchwork Mon May 30 19:38:14 2022 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: 12864922 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 A48BBC433F5 for ; Mon, 30 May 2022 20:03:37 +0000 (UTC) Received: from localhost ([::1]:51286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlbz-0003cY-Or for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:03:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlGq-000343-QC; Mon, 30 May 2022 15:41:44 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:33400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlGo-0000Qu-SH; Mon, 30 May 2022 15:41:44 -0400 Received: by mail-pf1-x42f.google.com with SMTP id w21so124312pfc.0; Mon, 30 May 2022 12:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VjMVykNFSdANRZcPdxEOZvf3FjrpzdUR9v+5Wsk8FiY=; b=NRijMvHPHrluRTx1/fJG7xO1/hSR/KabVz7WqC651C0lLUy7xspt2rdUmD1dEsO5Cy gSLGytrIAN65HHyNt2eQTVrALPJ7GwlQMpFSF+rvs2BI5d6lzArBf4PR3VkXBRRwanq5 06/yFofDn67m47+64ewoCaqSYWqLFmha9u05OkmeSSXHurez6W2nZO5nXcY02kh1CVDK Cegs82T/anJgXoRUmyjQJ8b75lirK6ivynBOsoSExu/L/P+WWE/xKDWOqSvzHX4KaoFf F2nVkZ5fthxTScrnzzRIBDYNrzrAgaEjb9M4KvLBplmsjCepI9End6xrcb9RVWZRINOn 3emw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VjMVykNFSdANRZcPdxEOZvf3FjrpzdUR9v+5Wsk8FiY=; b=eJkoxphUPwvo1F0xR7Ccfrx3h6tzJHiauSyqirqnjDwRdeDgW8Fn+zepyw42BAb+8a 53fIA/2yKHm46x8l8IWZiFbftC1TviVwLa7TytiyzUtBx+O2+Iljx+eFGqO7/1r9prqy CxgTSawDOgVvNeYC6LnN3xltNvr6wOOZogl/Im17YliBRORgzyC9DgK/5LQbPpavYaB1 vN4rvviwrZLgqhId36miYau1d/RRgboWpGgW0gcUpS6aL43JMNuIV8gxiZ7DEHrpJvx1 mjfEvICEb8K5UhhBg/h2baS1zPLOMjK11Xv/SxOqylNnbhY242N1YmOiecAyDVNsrSPl fZTA== X-Gm-Message-State: AOAM533mdext211giT25ENx3cG+basJVEbQGYQyjvYZ1ldYVm/u/IcAH hcR0V3WcohAZ4H6huMCF2C0p5EtfSbc= X-Google-Smtp-Source: ABdhPJxvJ8vitVWiIM82JJ/rx4Q3WHsMhcDdCoN1Tzb+eLdQnfI524Uycxy7XBCAnh4Ii/j8RnEpYw== X-Received: by 2002:a63:1716:0:b0:3f2:52bc:b4f3 with SMTP id x22-20020a631716000000b003f252bcb4f3mr48914944pgl.610.1653939701048; Mon, 30 May 2022 12:41:41 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id n1-20020a170903110100b00163ac8673edsm5680760plh.35.2022.05.30.12.41.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 23/25] hw/sd: Support boot area in emmc image Date: Mon, 30 May 2022 21:38:14 +0200 Message-Id: <20220530193816.45841-24-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Joel Stanley This assumes a specially constructued image: dd if=/dev/zero of=mmc-bootarea.img count=2 bs=1M dd if=u-boot-spl.bin of=mmc-bootarea.img conv=notrunc dd if=u-boot.bin of=mmc-bootarea.img conv=notrunc count=64 bs=1K cat mmc-bootarea.img obmc-phosphor-image.wic > mmc.img truncate --size 16GB mmc.img truncate --size 128MB mmc-bootarea.img For now this still requires a mtd image to load the SPL: qemu-system-arm -M tacoma-bmc -nographic \ -global driver=sd-card,property=emmc,value=true \ -drive file=mmc.img,if=sd,index=2 \ -drive file=mmc-bootarea.img,if=mtd,format=raw Signed-off-by: Joel Stanley [clg: - definition renames - Introduced bootpart_offset - Introduced sd_boot_capacity_bytes() helper (Philippe) ] Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ include/hw/sd/sd.h | 1 + 2 files changed, 40 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6722003cda..05e77f128f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -659,6 +659,12 @@ static inline uint64_t sd_addr_to_wpnum(uint64_t addr) return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); } + +static unsigned sd_boot_capacity_bytes(SDState *sd) +{ + return sd->ext_csd[EXT_CSD_BOOT_MULT] << 17; +} + static void sd_reset(DeviceState *dev) { SDState *sd = SD_CARD(dev); @@ -857,9 +863,40 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) qemu_set_irq(insert, sd->blk ? blk_is_inserted(sd->blk) : 0); } +/* + * This requires a disk image that has two boot partitions inserted at the + * beginning of it. The size of the boot partitions are configured in the + * ext_csd structure, which is hardcoded in qemu. They are currently set to + * 1MB each. + */ +static uint32_t sd_emmc_bootpart_offset(SDState *sd) +{ + unsigned int access = sd->ext_csd[EXT_CSD_PART_CONFIG] & + EXT_CSD_PART_CONFIG_ACC_MASK; + unsigned int boot_capacity = sd_boot_capacity_bytes(sd); + + switch (access) { + case EXT_CSD_PART_CONFIG_ACC_DEFAULT: + return boot_capacity * 2; + case EXT_CSD_PART_CONFIG_ACC_BOOT0: + return 0; + case EXT_CSD_PART_CONFIG_ACC_BOOT0 + 1: + return boot_capacity * 1; + default: + g_assert_not_reached(); + } +} + +static uint32_t sd_bootpart_offset(SDState *sd) +{ + SDCardClass *sc = SD_CARD_GET_CLASS(sd); + return sc->bootpart_offset ? sc->bootpart_offset(sd) : 0; +} + static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_read_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); } @@ -868,6 +905,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_write_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } @@ -2564,6 +2602,7 @@ static void emmc_class_init(ObjectClass *klass, void *data) dc->realize = emmc_realize; sc->proto = &sd_proto_emmc; sc->set_csd = sd_emmc_set_csd; + sc->bootpart_offset = sd_emmc_bootpart_offset; } static const TypeInfo emmc_info = { diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 8a0f2e75da..36d3cba08e 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -130,6 +130,7 @@ struct SDCardClass { const struct SDProto *proto; void (*set_csd)(SDState *sd, uint64_t size); + uint32_t (*bootpart_offset)(SDState *sd); }; #define TYPE_SD_BUS "sd-bus" From patchwork Mon May 30 19:38:15 2022 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: 12864914 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 B0085C433EF for ; Mon, 30 May 2022 19:55:58 +0000 (UTC) Received: from localhost ([::1]:60734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlUa-0007Tg-0F for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 15:55:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlH5-0003Wt-36; Mon, 30 May 2022 15:41:59 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:37449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlH2-0000RP-BJ; Mon, 30 May 2022 15:41:58 -0400 Received: by mail-pl1-x629.google.com with SMTP id t2so3442186pld.4; Mon, 30 May 2022 12:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pAi4+p0wY1bxzBZ24y5yNQYY9Xt3OVGw4T6z/yPKKqA=; b=JdHOckjFr+5bOy6bBcsfc00oIP5BCbQrmKojFaAaKo42wJmKmL28LCtegJfH7MOznD SSxEWGl118FLB11GnqRUu9ZxQ++K/x4MWC7TMcAXVfH5nWHjyxA8cO2H7Q2VFcGpQP0f f2B+RLJBP7Pi3NWs3+DOVk9RBx67uyPqMxlI7LchpMzFnuGZeHFgmuFeLMpbDLZdF50A GzvlM2Ezslwhby34Q0I1NVbnm8O8HX/BUP/lZEJ+9gJLxfju6N8LZeI8c8ckLUDu3U2E fUD3SDrdWUyWyMzMWcWLPx9woLucMgUi67HDA9TcvDocO7L5RPADvlRgbqbh+hcbT8fn cHqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pAi4+p0wY1bxzBZ24y5yNQYY9Xt3OVGw4T6z/yPKKqA=; b=gh+d7amlzPNNd5RcAqFIaBNSpxmM1aUDcAE8FJLLcZFfpi5gDagJlJlZnJY1VxkLXR kIqeiAz07HDtDY7AKGJrD5gKx5Dh9A7CqUbXmwGQX8grCDfkUgP3EOVNNF7wzExtA2dX mkYSIN8FC2ZqhLyR0KaPH5FIrGUfijzPHp/SN8MKPfxV75M+yO/wRD88xZ55z6CwCqnW pYQH2AbPbJeEjOcoHf+awvVBxk7AWxbHPRwWMkYXFnT3woqFA3dZOfyeENB+cDzK7OOi Z6yTtw9RoCgGQokW4Pm53nvAMFKGcGbQAd/4eeRrnjLfDNHyDpFOGK2WqW8b1LZ+LvbU Mwlg== X-Gm-Message-State: AOAM5336TgfyJdTVDvZMtAvPo1iBDDI8S1yylQAIhModNwtjthIt0LjZ tI/vQpHOhICfRJjEBHcpgj+up2dnnNE= X-Google-Smtp-Source: ABdhPJxzs0uy6ZsYQddbalLZzXfoSfqq5l6e83ir29YZgH/QGlkEIp93lpCxLV/tPS2NXegKqNdfiA== X-Received: by 2002:a17:903:249:b0:163:6dc0:b8b3 with SMTP id j9-20020a170903024900b001636dc0b8b3mr24582273plh.24.1653939709645; Mon, 30 May 2022 12:41:49 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id n13-20020a170902968d00b001621c48d6c2sm9474077plp.221.2022.05.30.12.41.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 24/25] hw/sd: Subtract bootarea size from blk Date: Mon, 30 May 2022 21:38:15 +0200 Message-Id: <20220530193816.45841-25-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Joel Stanley The userdata size is derived from the file the user passes on the command line, but we must take into account the boot areas. Signed-off-by: Joel Stanley Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 05e77f128f..26ddf3e92d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -668,6 +668,7 @@ static unsigned sd_boot_capacity_bytes(SDState *sd) static void sd_reset(DeviceState *dev) { SDState *sd = SD_CARD(dev); + SDCardClass *sc = SD_CARD_GET_CLASS(sd); uint64_t size; uint64_t sect; @@ -679,6 +680,10 @@ static void sd_reset(DeviceState *dev) } size = sect << 9; + if (sc->bootpart_offset) { + size -= sd_boot_capacity_bytes(sd) * 2; + } + sect = sd_addr_to_wpnum(size) + 1; sd->state = sd_idle_state; From patchwork Mon May 30 19:38:16 2022 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: 12864924 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 95F5BC433F5 for ; Mon, 30 May 2022 20:08:46 +0000 (UTC) Received: from localhost ([::1]:60630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvlgz-0002Od-Ks for qemu-devel@archiver.kernel.org; Mon, 30 May 2022 16:08:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvlH7-0003gc-Fo; Mon, 30 May 2022 15:42:01 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:44599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvlH5-0000S7-OS; Mon, 30 May 2022 15:42:01 -0400 Received: by mail-pf1-x42c.google.com with SMTP id g205so178656pfb.11; Mon, 30 May 2022 12:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nD26OrZMOffcOx8taOCGM7PEMXeUpfdyuSmg9FQvc1w=; b=qK9Pi323Hk/L9pv5+CmybvlhFJHYhsVRFp0nap1f1IGUfVsUQQuaM9V56eOZY9rkhW kMerMvz++RWOfUDwZ0xqyiWYUmVe44M3kJrL75xQQXnOtd9oCi8ZyBaQUrBHxzjNGLFT L/JrXcSUNc4sh0p4eW4DhvH28pJF/f/32UH2CgrRTWg9JK6F50XME/C/QIyF+e07HOfl Z8NJWaxfYb14wHOi6lFfOJE5NiDj5ror84Xs1n+GhzeeUhWoOYExMEfA5ItyIFGmTyPF tm7bQTID1FHp7gNQdREMks0aM7mHRGPNDx5R/tZoFq5V5KZD5xorzNhXypF4OXXMhCx6 0q7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nD26OrZMOffcOx8taOCGM7PEMXeUpfdyuSmg9FQvc1w=; b=y88VefsKSrKPDKNV1Lrs1GdHpEWeFAsJpk1lAbJDxA20JzpV9d6Hfpc+gzqSiEw6/I isn0QzRyLB8TgxjpQtaRes2ZsPbxb12cLNfGakeWh4Ej1K8TYNumXuCfjpzdxVc4kfcP KbXDlkRtoaIonCmcFkvvxmmQpvP76HZhPEhqhuPGwmh3Xi2pxWq2sR/0n4VDmtJEH/q4 6iBiTK8H3cUNsiiopApLSI1XaGrBpPCdKdHB5nJtgj8OxWOceALIJogK+qkrHKImjmoz VrJbkHa1z8+5llKwNpdm/UL8nBTdlnfJCW3E+OpzXaD8mioG273EO9eLYtK/p6AEw3yk y5Rg== X-Gm-Message-State: AOAM531Yc2vV/GvhI5k8gw08A/Up2Nk/oQSDTojAgY27ALR7ti8rgU+w SbVJ/9qZFbirEy84Lo+5zi1Tw2h1giQ= X-Google-Smtp-Source: ABdhPJzdfw3gxMLx9bHabC2NztCyc69EM+f86b6pOjvLW4L+7ivkEy8H6B/kc2u36RbaRRQsfDni5Q== X-Received: by 2002:a62:8206:0:b0:518:3c6a:21ba with SMTP id w6-20020a628206000000b005183c6a21bamr57096113pfd.63.1653939717997; Mon, 30 May 2022 12:41:57 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id o7-20020a634107000000b003c644b2180asm9071910pga.77.2022.05.30.12.41.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 May 2022 12:41:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , qemu-block@nongnu.org, Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Sai Pavan Boddu Subject: [PATCH v2 25/25] hw/sd: Add boot config support Date: Mon, 30 May 2022 21:38:16 +0200 Message-Id: <20220530193816.45841-26-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> References: <20220530193816.45841-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" From: Joel Stanley Introduced "boot-config" property to set CSD 179, the boot config register. With this correctly set we can use the enable bit to detect if partition support is enabled. Signed-off-by: Joel Stanley Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 26ddf3e92d..da909ec59f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -116,6 +116,7 @@ struct SDState { uint8_t spec_version; BlockBackend *blk; bool spi; + uint8_t boot_config; /* Runtime changeables */ @@ -453,6 +454,8 @@ static void mmc_set_ext_csd(SDState *sd, uint64_t size) sd->ext_csd[159] = 0x00; /* Max enhanced area size */ sd->ext_csd[158] = 0x00; /* ... */ sd->ext_csd[157] = 0xEC; /* ... */ + + sd->ext_csd[EXT_CSD_PART_CONFIG] = sd->boot_config; } static void sd_emmc_set_csd(SDState *sd, uint64_t size) @@ -878,8 +881,14 @@ static uint32_t sd_emmc_bootpart_offset(SDState *sd) { unsigned int access = sd->ext_csd[EXT_CSD_PART_CONFIG] & EXT_CSD_PART_CONFIG_ACC_MASK; + unsigned int enable = sd->ext_csd[EXT_CSD_PART_CONFIG] & + EXT_CSD_PART_CONFIG_EN_MASK; unsigned int boot_capacity = sd_boot_capacity_bytes(sd); + if (!enable) { + return 0; + } + switch (access) { case EXT_CSD_PART_CONFIG_ACC_DEFAULT: return boot_capacity * 2; @@ -2548,6 +2557,7 @@ static Property sd_properties[] = { * board to ensure that ssi transfers only occur when the chip select * is asserted. */ DEFINE_PROP_BOOL("spi", SDState, spi, false), + DEFINE_PROP_UINT8("boot-config", SDState, boot_config, 0x0), DEFINE_PROP_END_OF_LIST() };