From patchwork Mon Jul 3 13:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698670 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1749741wrs; Mon, 3 Jul 2023 06:26:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlG0uF3PhbTS2KtDpesW2r0EiZkB11HYCIY0wsIdzTf9tX6ZUC7xb69XWt/RK09U8A9JPe41 X-Received: by 2002:a05:6214:27c4:b0:635:df49:719c with SMTP id ge4-20020a05621427c400b00635df49719cmr13758600qvb.22.1688390800369; Mon, 03 Jul 2023 06:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390800; cv=none; d=google.com; s=arc-20160816; b=FNzd1pAIur/5ZNDxPUSfJGo/xWfDuT9YwIzR3ISKvbDuvnID09tyoKVtYapSBOVNul oHRxqZ+fLxGbvRQEiJXU+1bng5F7wUWZgrxE/FfVYIYY8g6UmbPhJ2x+4RR0IZCVmu1s A2TBlGJD1OfydEqa7KXWCMp0/BcctllhIxENGDPhNaTAq09pVCyUZLCU7tweywQ7FHKi othHebqlQpyiOMKWG1SngHe3Is6HjxW3I3MImQHR8+yC9xfwtJD8vlwdUatuWoXCu+2z RrN+IM1mS9JdtWipLlNOu1UzOWjMogO3Q72f3M1jtxzzpViJSJPyw4XCv/zXoAZCvauB O1LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=EGEDk8TfESpb2jaQTDwyMomp/1h2Qs+UivBpvTtwSFY=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=ZpquvJkNejmmgMzDpq3P8mlI4BLcx6/4Wb4Amust+Wus6Z2uEukPTdFzcb9SaNahcJ RSaYPNcsgCRQCG/2XACIOuNNJl1Sdk7iR/XfDj+LHrzCxmMTxBrZmpsoLigwQPC9KmSw d+I8L2oRsbZhkbrLlJ1gzlq1smC9YSAQXTzE8ZLU1oB3XyMXhR222Z5Z5a9PPPyljqTl 6+WTe0HdYeFd27dypNEwOgjoe5CNUf2nTwPjEILB486lGdqGf+1R3JdRYHeaRIDIKA/R +5axnUEE9dB+RvfJpPwH4xp50hQz7FAvf3LhYx1GeSehfDBM9ZJlDBNIyVPfivCZE+7Z Yt2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gc4-20020a056214230400b006239d6bb9a2si12132654qvb.512.2023.07.03.06.26.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYY-0008Od-7Y; Mon, 03 Jul 2023 09:25:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYU-0008Nb-Ov for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:27 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYS-0000ak-MY for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:26 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4QvmrH6RXSz4wZp; Mon, 3 Jul 2023 23:25:19 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrF1KnBz4wb1; Mon, 3 Jul 2023 23:25:16 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 01/32] hw/sd: When card is in wrong state, log which state it is Date: Mon, 3 Jul 2023 15:24:38 +0200 Message-ID: <20230703132509.2474225-2-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 0be9ee965ac9..4412559c05be 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 Jul 3 13:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698677 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1753604wrs; Mon, 3 Jul 2023 06:34:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlEeilPiKCxPkDDfAtC0+qjtA3TLCDD9eU7dPq5L2JJAz0nPNoIfpBUL54P5P4DGiiXuq8sj X-Received: by 2002:a05:622a:208:b0:403:5e74:e833 with SMTP id b8-20020a05622a020800b004035e74e833mr2318482qtx.39.1688391276903; Mon, 03 Jul 2023 06:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688391276; cv=none; d=google.com; s=arc-20160816; b=WrZbrCEo0x+8ORQadQbi5klFyIXb+J/XCarkuEA0gjOvzBg9UiwiM6iwat5Vkv1h/b wPmOQH+2VSHu7A9T/00TNzZSXqLrRpVSJ1M/0b+l/w34g2Wvasi0EARZlxXt30Fj4+Jl KJsumxGcgcYKQqjk1JuIVTeHx9nHAHEeIObRqw0032rmUSkFTfBMU/sdmg65OQ0SrDYO NZOTh4fwJv+5SgAh9If8WNgy+cDewKm4L29dquilze/JTOBnGq9p2RuqFagFBGrbwcIv ED4LUHV/ArayZJYYWSfloWBLVq4cBr17Q9oR31h8AIO0J2wfu2wYZkXjAFyKLp4J7x61 wEcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=1BLIrNyVfCivsjfZ5ORSKPavJojsslslzD2FBIGPVoY=; fh=1TrT0PYyEK7er4Ab9GZHs8q84ATye5Z3OY6erb1zI7k=; b=TxPBZSVCg0MTqDEhp+24c1C7G8LIVi6zCqUN+dCJajGyGIHQ1C4uEvWmBTqJ5pNUWv OVFgBj3xC3oh9HbQc+iLJr85chItkMM0upEANJQKpxydCsYPt5RsCZ+RToOBpyEgmb7M 0mdH8I4zScLE3QZSU6akL5Pvq/o5NH0s5ch/PB5tKv/goangDpiClfJufsPCovf/T1dj G2pHVHFvHs1Oh1vkFE6/U1ydsY92cRa848jEBxBnN3+V1sXEIaBzda9iIDFhO3CCU42V 7zOa+hyR/xP8AvGAVCpejEKJKvvKSei0xVB9BBkWiTHdZtazva/DltfUl+pPSEeCLGgE aP7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s13-20020a05622a1a8d00b003fdea42e025si7800855qtc.362.2023.07.03.06.34.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYZ-0008PD-Es; Mon, 03 Jul 2023 09:25:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYV-0008Np-JH for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:27 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYT-0000en-Hr for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:27 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4QvmrL6Qscz4wxn; Mon, 3 Jul 2023 23:25:22 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrJ38lcz4wb1; Mon, 3 Jul 2023 23:25:20 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 02/32] hw/sd: When card is in wrong state, log which spec version is used Date: Mon, 3 Jul 2023 15:24:39 +0200 Message-ID: <20230703132509.2474225-3-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Add the sd_version_str() helper. Signed-off-by: Philippe Mathieu-Daudé Signed-off-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 4412559c05be..20e62aff70b6 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 Jul 3 13:24:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698667 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1749554wrs; Mon, 3 Jul 2023 06:26:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6oa8QPILeOJzBot6f5RkYIUEobv2UaN+dXg7uKqspLtnDu/4n2kHbmsa1dKtmMYHXOblD0 X-Received: by 2002:a05:622a:11c5:b0:3f6:c064:135b with SMTP id n5-20020a05622a11c500b003f6c064135bmr10755399qtk.54.1688390774417; Mon, 03 Jul 2023 06:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390774; cv=none; d=google.com; s=arc-20160816; b=fH56X3mfcu+9z4Z6qT8YRm2iVKoJDel9IGkEoaMP5QISY1FUMq4Hrq3EAPTcse7DOI dSVQ5AtPrBrU60nUEUGHPNa/RmeG3VHs8OjE9vBWqY4hW3BxV4vCzBXl+xLIRzYWn3ZB I13s4RYucVa2qSqx+SHd0hYSquyWUV9UkDbeNCOoSPujkv8g5GusTTR4zX65rtDAgeCI tLvyVqVpFqXuY4PBsPzHv+XhMaswzo+RRLNdJrJvZ/HVdnGUy712FvFLICJ01VZrCX/n 5wom3QkEyRRhIUVWwf40U/bd5ulE10gdp6TOahrrQ+J1Z/ljsNsGmptghUmdU9EZL/xK XZKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=tV2VWfI9PPTQsJIFMDoy9fW8i/ErdqhNHMgDRfup6Hs=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=YNU2/qz1CWDVDliW8qG4QvyyiV0af3N4vtoPDFiHYcjyaMDe0Py2t8c6f2jfJ2MUWA vNlWnks5A9Mtmty/Slr5fV1e+Qgo00sWxdZXxQdryrkZGb4RWNx9Vuq2liZzNb47hkBJ RQPXKhx2CINm5z5MvZS7B9VqTJQiJLrPxp3D+wn3vHwSTnI8J9VW/wKMXqpeKJ3+mRWl HQnxX8Miuox3JPwelkwHkCN7MGyoJOvdzahzag2nLO8yVs998kG0hRkaIYlN5f08Vcum wlDgzWMWtXAKrqIDVHT4FznzY6wBYeTN/8WTzbfNfznW06+oFp5xx3pdoZwEQITrd7db hi3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d21-20020ac85ad5000000b0040331af369csi6496673qtd.266.2023.07.03.06.26.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:26:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYb-0008Pi-3X; Mon, 03 Jul 2023 09:25:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYZ-0008P5-68 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:31 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYW-0000j2-Tu for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:30 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4QvmrQ18tNz4wxS; Mon, 3 Jul 2023 23:25:26 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrM3B7Vz4wb1; Mon, 3 Jul 2023 23:25:23 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 03/32] hw/sd: Move proto_name to SDProto structure Date: Mon, 3 Jul 2023 15:24:40 +0200 Message-ID: <20230703132509.2474225-4-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- include/hw/sd/sd.h | 2 ++ hw/sd/sd.c | 35 +++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 3047adb2fc86..b322d8f19b17 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" diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 20e62aff70b6..f6aa3b0a80bf 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 From patchwork Mon Jul 3 13:24:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698674 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1750335wrs; Mon, 3 Jul 2023 06:28:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlHnUqI21OzGLOm3f72AynmCzzy2O04WjxXeBTE0OgZhwk4BCY3lNc0tMoA/pydS8O/z8oY+ X-Received: by 2002:a05:6214:29c5:b0:632:5fb:5642 with SMTP id gh5-20020a05621429c500b0063205fb5642mr12265511qvb.12.1688390889543; Mon, 03 Jul 2023 06:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390889; cv=none; d=google.com; s=arc-20160816; b=gX6sAggJc5RId76r6bHzyVCHcx/uFv94UzqCZphIkTfFJ0l1XUZAH4T71txuUFdJWd SjHtPyEue6KY35ZmeCz6Y5l8ypmoqahHJsj7C2fUema5l1/WVtJnnoVhaLzLvsEq0qoq F63i838bn2q04tFRfyhU7Z932A1YLkow00Puv2/CTsYCgg6Gtft2ryX4HfsXmahpO2oa CcND98O3lnwTP8iR9vUDQxML3iUUG2SWzNf7ksQj6erlGAcRTlCX5dNuiQA+3NH1HHIQ 2H5fx6Zl07Fb488OqHnZj7Vl3t7g0lTzajcmQziV6a8M2BWH0Y8FnVZ2ZaqWZuJhwWHa cJtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=MeJFAgG4cWqAaKn+PJeZ1uhoAB5/zbA2L09zHFX4XaY=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=UhHmUz7VTsUGv6o4P0YvFql+FGLslpQ2DrsLaY+HKY6coZMi04jdAkjwhE9J3TnAu6 UHtq8Me205JgGoEZJSd6RX2ErBnloRzbALWkao2Eh2WpSQmz9hdSQGW9OS6hBhdzRiSa 5MuE94bRKrpqn1VoLsSjgKvUqaGulrsuYUMDTuDth+2vNpzmZsMEONytkGGmxdHAVMtd PHdvZDB5+QhKnotNGUc6r53y0Zi4xpLF5bEJoOtxhyKa1yffvBB45YvxbtudncOnz38F 7FXCzod9aAim5TGWqzcCQZr2zEg3Qsj6/Er8Bj4TpN0l4FQ/+6REffGFzzFgm8CYZRbD uZng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gh6-20020a05621429c600b0062dddf078cdsi2804373qvb.48.2023.07.03.06.28.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYd-0008Pt-Qm; Mon, 03 Jul 2023 09:25:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYb-0008Pj-3M for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:33 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYZ-0000je-Dx for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:32 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4QvmrT31gzz4wxp; Mon, 3 Jul 2023 23:25:29 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrQ51bWz4wb1; Mon, 3 Jul 2023 23:25:26 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 04/32] hw/sd: Introduce sd_cmd_handler type Date: Mon, 3 Jul 2023 15:24:41 +0200 Message-ID: <20230703132509.2474225-5-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 f6aa3b0a80bf..889c44a5c07c 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 Jul 3 13:24:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698676 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1751017wrs; Mon, 3 Jul 2023 06:29:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7l3QA92RK9TVyEjAHzmQ9jk1oUKvjaqTQREe/XuHUXd4KosljQatCKoOHJrxuNAOPJ87Xd X-Received: by 2002:a37:ab13:0:b0:760:6b8e:eba with SMTP id u19-20020a37ab13000000b007606b8e0ebamr10269203qke.12.1688390978368; Mon, 03 Jul 2023 06:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390978; cv=none; d=google.com; s=arc-20160816; b=UEXdj+0DGkpXPCEeZXwMVh8IbsLk788/XabcZompw/U87w4e1xSzOv8h4yGJO9WfeB zJ4/e3CknaVpxIBZ3aWkoX5iV6VN6Xr0dvXDw1LSNAmgut7FpgUYObhf+HdeF7GsPqPx Ww0GPRn7ra2Km+I/z29ShctOIkXBpAJcnS1PSUllLoT9x8Jd7yvv9umpuZwws2n61air RZw5mk4Ze1vRqyT7JZhpJ3Xy+y4iOZh7QtFM+pZa6xxL4vubh6bNX+FqlRi5xnoU2GUu LcFttDezMsdpIEljMVQqYX+qcqqv2tCQSD6hl0bZwE+FcL2Rc8H/nphfuWWQ1+hmRD7Q +qKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=JCeGC9ebRZzRvYWPhy4UWOUWojZR5M1I9bh6ICrwjSo=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=KgYgtrxQJABOoLj5pFTpu1m0VX47fEUZYQ8MUiPpprjF+ePcrshLh9r1Jq48kaEdMI DUuTuSIJx0Lu2GBREf7hwzY6tWxmj1tHD333JRI/d7I1cASkCabVUW7RSdkpWMXom8Is mNfgRLhKxkLUOJ2TtUaMBRiNbCZUrEsN7SO2YK+CmOpNLaxRMcv+KqL/8U3Fqz/48est yY1EXtauda/3hPIFN4rt2pAcO2xtBWILwoROHlyntU4vWTbl3UCM3rl2DbazWlKi7yU8 7O7YG2FFPYt9q6xcu37QKkvdlQbPr5CPtcVsvUNCeoRcup2ET0r1BLKtNyHXUvaiqwZz dBWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ty11-20020a05620a3f4b00b007673316a71csi6635153qkn.570.2023.07.03.06.29.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:29:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYi-0008R8-M8; Mon, 03 Jul 2023 09:25:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYe-0008QF-P9 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:36 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYc-0000kE-LC for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:36 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4QvmrX4rZGz4wxm; Mon, 3 Jul 2023 23:25:32 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrT6vYPz4wZp; Mon, 3 Jul 2023 23:25:29 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 05/32] hw/sd: Add sd_cmd_illegal() handler Date: Mon, 3 Jul 2023 15:24:42 +0200 Message-ID: <20230703132509.2474225-6-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 889c44a5c07c..83a0d6825147 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 Jul 3 13:24:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698668 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1749580wrs; Mon, 3 Jul 2023 06:26:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58stZIth1/qBbVeYprdNMFM8T4munqvUzwWoXgOXGFymjcGzRwyDCKzhw64VYuIHkblz// X-Received: by 2002:ac8:5f4f:0:b0:3ff:2179:c48d with SMTP id y15-20020ac85f4f000000b003ff2179c48dmr11744074qta.28.1688390777466; Mon, 03 Jul 2023 06:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390777; cv=none; d=google.com; s=arc-20160816; b=HL2feGoBA79lJYvMBxz+dKoVxPnzF4muZg543twYT1emSquY/n25S0FVGK+S6Bu+ny +Uy/cLIJ+8kH4vpnzkpKwY9NsewNFprdYdpgmZG3sgp8+yAoBzOfm1C1ogeC9XXdrFoO 77iYENKqapuitYN7/bmCWqNDsG9CNwq3V3QSF2Esjpma8s610r71DpMgWyKg03A15aEO 4EcPOse9ocXRNS3RrcyO3TQWYAj2YElrcHBJ1cQv0xzJELWJ3RXubN2R7X+QRk9rWYIa qTAmqlPsdUVmD6N/b3eY7YRansYMFTUnScu72yMYSW5Bel8uqTOUmR7wEAQVoQq1ZUmX 2LrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=iNCZyiLgNI7Uv3B2DtI+CbxKLRcsCcU5ZsEydQgu5gc=; fh=1TrT0PYyEK7er4Ab9GZHs8q84ATye5Z3OY6erb1zI7k=; b=ba8g/HqqFyRxf/Uht/NzQzwJgfGpx5eso8W06y9GxT7VBF7oLdT+efm2I7REbBDzKp SfimS6Iuqaz/D6MavGPm8Q/qX+HCZqYwjPQ99vtMTpAvPdV/F8Imari0fjJnw/RtWJdi KgeqQ9FTAJGmshISDYKi37ZXKuI9jb4Kr8902v+jBJeGm0tyCrjO5ECLvPjd8/K+StYr VsYG0v66Fk9M1YWRlMiy56Is2JhSgdWL/V/SBPKMckUBWO+x6GulqCCDD0ViU3n3HjH+ Zl+YX0ndNdDLB1iSaCkUDd8PN213yox5USNZ8nPFaeZnBqvPmJbte6D+T88GzMHKzkLP 3XCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o4-20020ac85a44000000b0040340990b62si4912348qta.383.2023.07.03.06.26.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:26:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYo-0008SH-9p; Mon, 03 Jul 2023 09:25:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYj-0008RX-Ia for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:42 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYg-0000kY-NV for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:41 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmrb4kT8z4wqZ; Mon, 3 Jul 2023 23:25:35 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4QvmrY1b4Sz4wxn; Mon, 3 Jul 2023 23:25:32 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 06/32] hw/sd: Add sd_cmd_unimplemented() handler Date: Mon, 3 Jul 2023 15:24:43 +0200 Message-ID: <20230703132509.2474225-7-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 83a0d6825147..e88bfcb8c802 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 Jul 3 13:24:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698675 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1750548wrs; Mon, 3 Jul 2023 06:28:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlGp/lofezLQV63bdfxBlB9bPRRO4biWVSFNweFbn+WAEXiiH4Npo2BPTn4eMFkz2/oE10pf X-Received: by 2002:a67:af14:0:b0:443:6b27:65ae with SMTP id v20-20020a67af14000000b004436b2765aemr4491109vsl.24.1688390923710; Mon, 03 Jul 2023 06:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390923; cv=none; d=google.com; s=arc-20160816; b=KtI4SGNk4sANAH5PlwB+AuNLp7RUgP1FvKA1z+4f/5ZISa57Zu6XdgqD/f/ZuBzAvJ joR2KR46UwC14+6IUnGHscGOulSZQhrLX41Y9icWeLEGT/LjCzp2XpenM/SGL1kQ6p50 KcVw5iTF8x2SthwIe2/E2UrvTWtWp3H3FapzlyLTVa+UO2Kc13p7pQHtVcXQ5zal0KDK +QBsgEci31XmqSojG94rN1NUVWA4wwjMVSqbwWSOV3V0nbW1+0webwb7fvU6OPGkKp3r /bb0La2n17Db9fVAcSuwB1b5rdiNWu7SLBsTCEQ9AlY0f0SKI8/pmLCGNb15uRyi1VW5 JfmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=laSCXRuI0WgUEvINvw9vpQy5W/8jzIb8mbvxlhYEp5w=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=Lwcb4OSr2oD4ql+vv/iEnYDLvmL36RC/Jf15Ui0zzwp9QpjqUZxoj0NlS5s3EpSCb4 Pf3HVpVIksKE4aHBaaJio8o9ki4UDVW4IaufgzcqyGLfCUY70LJ+4BjzMtwb5n84T0Gc Aw54UntUCYwW3cE73QDLRTFvA8FNV/45B/cwFWgpF9Nw6/kotz/J1hn8NirSwerheBxO f0btgsLdA+tD/uitcst2b3ux+vC2ZrJx4uzjowJnYIKWU7n0jTprH/YER4CYmuIIbAH7 g/aX3phwanIQuConPERxLvJCOLBiSeGoY3L4AKhn4QKw+mU3bS6qKJ7t03plyvnm8U9f rYfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id hu6-20020a056214234600b00623a69d6e7asi12077364qvb.390.2023.07.03.06.28.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:28:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYq-0008Sa-CI; Mon, 03 Jul 2023 09:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYl-0008Rh-8q for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:43 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYj-0000lA-Kd for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:43 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmrf6X1nz4wb1; Mon, 3 Jul 2023 23:25:38 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvmrc1S9cz4wZp; Mon, 3 Jul 2023 23:25:35 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 07/32] hw/sd: Add sd_cmd_GO_IDLE_STATE() handler Date: Mon, 3 Jul 2023 15:24:44 +0200 Message-ID: <20230703132509.2474225-8-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 e88bfcb8c802..535b72ff5c2a 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 Jul 3 13:24:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698671 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1749778wrs; Mon, 3 Jul 2023 06:26:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGdy93GZeZ3hzUsegGOeMAVtW5YfdzIWdNsVVJUA9tLeZYNYTWHOJapB9rlgd5T5Nk8X3kP X-Received: by 2002:a05:6359:6797:b0:134:e4fe:e162 with SMTP id sq23-20020a056359679700b00134e4fee162mr5449514rwb.13.1688390807644; Mon, 03 Jul 2023 06:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390807; cv=none; d=google.com; s=arc-20160816; b=W4yfEXCZC/SfUr/nQ1gfAiXjhFf03WYEtB1FtHJSPxxFqw/gLLcwtVKuI9HJA3pxA5 0rssEU2vXAqDZvoj2C5NQH34lQkkYceeyactplZY9tvZFBx9DMRDYt5PxVGoHP8h7rn+ Ma0Y37aPmJ+lLDeu6deEAYxP0Vk5U3zYYODMDfoWZqtXyAdwMPUuCTEakg+v+ec4QsvE Zz/s4zNFYM2P8QO7dAS7S2pF9uRjuSmAsP/PH0TKn5XcSYlrpg+HG1Wehzdmg3YSptYO o06mazUQWgBgmamM0DhPcMZ2DhlbXcosSkL++wLGygiqkjkpa+dRQY5CxrESGt43tVnW 1YLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=xGJE5HZteIMYGPvh2ElraRI9/2W5TopZRK40cQYCvkM=; fh=1TrT0PYyEK7er4Ab9GZHs8q84ATye5Z3OY6erb1zI7k=; b=U2kBwmqyxiS30qqqFFGUzUDs0YASOQLqeTjLCkZ0RPsFDTIimIqPl1sTGGjMvdrkGM AyDX6X/97o/jnkAA/hywD/y+r8B1l7AGluynllj9A5veKFiuxaXQJ6OchBkNGEp27gMo LW9kS9C+J8irffYEK+eMOMTcU4B8BdQRH1MqTRNEKAsSBsgIbPS4vtNtRoB+uwFMGKOs +5Iv8maaQHzfSqJV4SJHsuAyOh2Gk9TMlPolUtvhDWdydcjBtuhBRMCD/a8HMhlVrzTw VVQMNwyHR/vFMu+xRGDbQZtITbcyZbNPpUv1WtRZnF9q1HE+RVIpZnKsUG3Unq9DtHzF iIbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f12-20020a37ad0c000000b0075778fd36aasi9612234qkm.709.2023.07.03.06.26.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYv-0008So-7R; Mon, 03 Jul 2023 09:25:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYm-0008Rv-2p for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:45 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYk-0000kY-H0 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:43 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmrj6NgXz4wxn; Mon, 3 Jul 2023 23:25:41 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvmrg3DHTz4wZp; Mon, 3 Jul 2023 23:25:39 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 08/32] hw/sd: Add sd_cmd_SEND_OP_CMD() handler Date: Mon, 3 Jul 2023 15:24:45 +0200 Message-ID: <20230703132509.2474225-9-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 535b72ff5c2a..bd67c50894fe 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 2053def3f10b..8648a7808dcc 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 Jul 3 13:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698669 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1749660wrs; Mon, 3 Jul 2023 06:26:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Nv0V8C59fdiO+XGZR280nfKtbtG5+GM4cSeHVQEF4V8Z78PT4tDxTsk9euPiC9H1r1fTz X-Received: by 2002:a05:622a:15d6:b0:403:38a4:4cb3 with SMTP id d22-20020a05622a15d600b0040338a44cb3mr12240931qty.17.1688390787530; Mon, 03 Jul 2023 06:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390787; cv=none; d=google.com; s=arc-20160816; b=VIzpQXUln8B6ieXqsfWmHnFFycREYJSNaRT9CzuStuma/cQpQMrje/y+GSXy4z/q9M MUAs/x5luoDk/poTEKfw5D3pgv1s8oyAdLmDZm4IEB/3CH6Cig80zgybcGN4jtDKe8pp o7PyQzl2xtq6Zgj9znl+nwsSD0QYwVZmxg1j30YHzF3PF0JZDYG/cBTWRRigplpMD87g uxg9ulnSDrRMQxSnH4UWHvc8zex1S7kZYMXRaWreVhzmXjmRgD9w8wYv46Nv/5sQmtIa 0DZVySSGOOFuSdNI3E0rfEeXR5ZAYKuwh+5d5sdQUQrRU3NrWbRQO4yBQOrABWRK9+XJ GzeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=qSahDTvOpdP8Uwj86S4Y6134kWqo8gH4wa+x+/ijE9w=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=di1anN0xHKXkyaHxIARnZhCHQ4sWMVzSH3ovcQlnU2ggpkAfYI88OXyx2n+aJqXZKi ADersCt1RmnWAq2/GxpC+xdP50EE0GZc1q8gVL9maRXFeBY+50+zMwRIJ+l8WviLaVYe 6nZcboluK1RWn3+xeyiUGXNcGYo3mwIF1g2aLPJVWzxUJcNf6zpB0YjIK+oOQfRIiAof YPR5RRJjH9Ou6NJdlkaJpATGFSlbSPcRZB0YydbEpTjWNJp62vuH0Q5jpvLyFQkX80fZ FPOHY8tFcqPZyqBWwbzQ487pwyjjzmN+NcyEiOroOPPn1ulqTQzZLzOcug1sKiLmWCwI eN2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z11-20020a05622a060b00b003ff2606751dsi12019862qta.177.2023.07.03.06.26.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJYz-0008Uv-7A; Mon, 03 Jul 2023 09:25:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYq-0008Sn-Rc for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:51 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYp-0000lr-5I for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:48 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmrn17K6z4wqX; Mon, 3 Jul 2023 23:25:45 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvmrk36Lkz4wZp; Mon, 3 Jul 2023 23:25:42 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 09/32] hw/sd: Add sd_cmd_ALL_SEND_CID() handler Date: Mon, 3 Jul 2023 15:24:46 +0200 Message-ID: <20230703132509.2474225-10-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 bd67c50894fe..33ecff496ade 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 Jul 3 13:24:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698672 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1750267wrs; Mon, 3 Jul 2023 06:27:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TlO5XJnqL7JgzjBWtafFFfkopMhsOVoP7838QsnKjqHw1JM8UWoFSnV3SZw4xW4TFffM+ X-Received: by 2002:ac8:7d46:0:b0:3f0:a426:5f29 with SMTP id h6-20020ac87d46000000b003f0a4265f29mr14954694qtb.11.1688390879762; Mon, 03 Jul 2023 06:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390879; cv=none; d=google.com; s=arc-20160816; b=p8TMq/CyYoDiQIFVAAUaqHcGIsK4/Ond84WjS9WO5XaZA5ucBsbvaFahe3YIRKdbjE kWbbTZWTh15TVnnl+4lhh9koK/24Dh+9FcvYrA2Uu3RmVR4cvsJooS5K3Yio2gar9gLT zlqWqdj/bSb9q8lC1yzc9W9WnXeIvwWdQQ1IxvEi+UuRzM6RTUGqDaSt8AVFSQw5Q054 OqXiFYbL+nZE1ly635ANAonsaNp/XzNUgXVHjCXN7YoOii5Uq/01dDp07d9eodR2rAlT 0RJ19XtD2prlkyv4w9mni+auRS3SpxgeLGeLBptABKrdZwikgqhEpi1/sdSWO1GRADmm N+iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=+CTTTKQHko9I2Piqkl0LV9I1BDWlxcSVOegYIjRRIco=; fh=r4syDaV3G3LiWeo8FbYKgqn+w8cwBFTOjL41cVc53DU=; b=wIT/S94WfX58iO+inJ/0+g23RreUwT7mR2Oj9A2yxvqZ6cCma7nrTM3hRo70qDp7IM W+MmaSAGajW6tic0DXm2giO7dSnF0Da87IJ3ftsls1sd88NYgwWSjFAvn+OdicNqbUtn 42fbrbLe4nyFpuo7X7wkaFcsV+9vOUXffh5SsNBNC2c2H5ayxTiYaQHYn2pCoNdpz3Vn lGicD3Qp8/8aVz67JbuLvY7uYJYdIQXr81rAf6BTgDxRlUhxDirFsKwYX6CNj7+6KDEd vIjSlHhMIcy1eGzdxpt+SXvgqsVa262C/2XOXoSSpz2mZxxlWuQISI8n3xUWkR5pSRZr xzRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTP id e13-20020ac8598d000000b003f3908aec35si11843536qte.660.2023.07.03.06.27.59 for ; Mon, 03 Jul 2023 06:27:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJZ2-00006L-Ux; Mon, 03 Jul 2023 09:26:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYv-0008TT-DJ for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:53 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYs-0000mM-Sk for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:52 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmrr2sR1z4wqZ; Mon, 3 Jul 2023 23:25:48 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvmrn4x6bz4wZp; Mon, 3 Jul 2023 23:25:45 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 10/32] hw/sd: Add sd_cmd_SEND_RELATIVE_ADDR() handler Date: Mon, 3 Jul 2023 15:24:47 +0200 Message-ID: <20230703132509.2474225-11-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 33ecff496ade..b46072424108 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 Jul 3 13:24:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698673 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1750321wrs; Mon, 3 Jul 2023 06:28:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4WmZuCk2eWbvHLOR5R/GeCL8FpJWMKZZfe2r0ez1B4Gz4aD+iGqosrTktXEeu/28ny5+Ot X-Received: by 2002:a05:620a:4116:b0:767:35bc:540a with SMTP id j22-20020a05620a411600b0076735bc540amr15000557qko.17.1688390887464; Mon, 03 Jul 2023 06:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390887; cv=none; d=google.com; s=arc-20160816; b=j144+tTpbkTOtsqMw4wJlvSN7vHenxBkpVuiT5fG5DG5U5qbvIZRJVRrm4IV0daM1b e57dzbOC6Dr5gFr+XEm8QmFnH0hRO3UNtDQE9sbe8yzExpeCdTsOxXem/3gJ73CEI6XF evMZH+I2gneiLSD4uglbYPQJa0bMZ07mSRNkCGxz7/kKjeuo9zhXKquIkVkrXxOW2qfK gNJhT7bAXoX8IoDXdMdAuvkxjAm1scn2pK9byHz+2Uy5GnU1Mxn5q+m90i0LvFqnHe9O e9oIy7rTT3G4h1s8V+qtnE2I5tljgrp0IXU51pVlolkJL5AwJCBo0M9HmJbwiRLlOuJZ B3pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=kfrxVkkDpSbWy4zcrLc72DNUkVBubZ8PY78R9b89HKU=; fh=1TrT0PYyEK7er4Ab9GZHs8q84ATye5Z3OY6erb1zI7k=; b=RY7+I3Wn/ZNS9CbkfhzOQsAV2zpfDb6pgVmFAVuUpfJPRXh9e4yWWR2eEz2Diz8WKs 9C+FbJydDDnohOrzXj3feUdE5hUmfnLZqSS6HCMb6HQVX0y7Z6OuA6u+UBXtYNfs9vTy kbFD4ZbKahYBDgRaX+xEyNJ2INAdeHXI6ON1p6hUpphcrd69skH4cUep/PMJRGLvtgfK GtNdZ3IdPqILlXwL8LXuFx9nU5WEIC8gFDCs+z/hrTcP9zn4xotV2AOw6NpHCUqglf25 doFV7RdthIsyXNOsU/LSrVSh76lO5vQ01fKTy/GR84Zuh2P7wky5bU32Wfyx4jBkuHHU 689A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x17-20020a05620a099100b00765a6315442si10351591qkx.321.2023.07.03.06.28.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:28:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJZ4-0000A9-Nm; Mon, 03 Jul 2023 09:26:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJZ1-00006Z-47 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:26:00 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJYz-0000nL-6F for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:25:58 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvmry4g9hz4wZp; Mon, 3 Jul 2023 23:25:54 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvmrw1Wrgz4wxS; Mon, 3 Jul 2023 23:25:51 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 12/32] hw/sd: Add sd_cmd_SET_BLOCK_COUNT() handler Date: Mon, 3 Jul 2023 15:24:49 +0200 Message-ID: <20230703132509.2474225-13-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-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 00a59450b726..d1c0b132c227 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 Jul 3 13:24:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 698678 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1755059wrs; Mon, 3 Jul 2023 06:37:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlENOtWIuMOfZoDlLXO+E6iXo2rfMu+qKiGo2dOZ2BsO1mEXoHPKD7LAavtdhuUGvJlPzTx/ X-Received: by 2002:ad4:5cc9:0:b0:635:f3c2:e88f with SMTP id iu9-20020ad45cc9000000b00635f3c2e88fmr12023530qvb.33.1688391460032; Mon, 03 Jul 2023 06:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688391460; cv=none; d=google.com; s=arc-20160816; b=qw6sdYXI1ym/q6u24fnyI3R0ug08GbtzAzxajQZu3okV3wWQCgAhcQ9iVzqMP7svkR lco2QTs7ILpa98pIXh5bBIoLFqYu7sXPhWw+wo29WVLl9mp0viWbiVy2e5ioBHdAEosO Rc2mQqYxWcXic37k3qavwvTyrIN24B3hvkoE9hW1Xwd+az8D8Zux83954mWFteUzpiej 31qgWj7EhQSx6zkNhPwa8JhwwcRDU4mxhEQYq2QyK3zWpY5yBgsr7p3sS/qesJpnwZWh owj/CYU8RtK/tEriEANBrlaCyKCveEMPW0oc1UgOLPyentznZNTllJRtrkwzUU4bsnZ5 v3wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=YDHsc8T11o7nqfHIXKtCwbmZOjk0kXgowsn57lzGibo=; fh=1TrT0PYyEK7er4Ab9GZHs8q84ATye5Z3OY6erb1zI7k=; b=c/h8xQo5Up/XeyEFE068r3YEVlxMTxAWK1PQ0VjAfiW3+vgZT/4pbmxiCUZMYRFCKX qAkU01/v9s4dORh+EtsLu6hRq8q2L6QBjLL1YPr6V5LryJCiy7Ze2v5N+rlDls07Bb08 EJJVlYgpt8bcEUZTsAES97r1qBHYjd+0RRzFdbSvy/N7n2Y/sZT9233WkXW9ZSrfJqU1 50OUfcIh9Gl5GXM9Lin+IGoTp2Tqwf6xhyO5uyZJe8K2v51+Y+fizNLjGgMdL1YlEo0/ ye/Oxmt9GWY8lhT4xZmikykFAVLimHn0LHfEMahGn/htZhx5rlEDhWi8gqH8qKGBMH51 vjQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r14-20020a056214124e00b005eee3411598si11925303qvv.145.2023.07.03.06.37.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGJZ7-0000CT-JC; Mon, 03 Jul 2023 09:26:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJZ6-0000Br-1p for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:26:04 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGJZ3-0000nL-4d for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:26:03 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Qvms42TRbz4wqZ; Mon, 3 Jul 2023 23:26:00 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Qvms16R0Dz4wqX; Mon, 3 Jul 2023 23:25:57 +1000 (AEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , Peter Maydell , Lucien Murray-Pitts , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 14/32] hw/sd: Basis for eMMC support Date: Mon, 3 Jul 2023 15:24:51 +0200 Message-ID: <20230703132509.2474225-15-clg@kaod.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230703132509.2474225-1-clg@kaod.org> References: <20230703132509.2474225-1-clg@kaod.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=mKPa=CV=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- include/hw/sd/sd.h | 3 +++ hw/sd/sd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 2c8748fb9b97..da97400469a0 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -96,6 +96,9 @@ OBJECT_DECLARE_TYPE(SDState, SDCardClass, SD_CARD) #define TYPE_SD_CARD_SPI "sd-card-spi" DECLARE_INSTANCE_CHECKER(SDState, SD_CARD_SPI, TYPE_SD_CARD_SPI) +#define TYPE_EMMC "emmc" +DECLARE_INSTANCE_CHECKER(SDState, EMMC, TYPE_EMMC) + struct SDCardClass { /*< private >*/ DeviceClass parent_class; diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 03fdb3addc38..409fbbcbd8d7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2171,6 +2171,20 @@ 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, + [23] = sd_cmd_SET_BLOCK_COUNT, + [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); @@ -2307,10 +2321,40 @@ static const TypeInfo sd_spi_info = { .class_init = sd_spi_class_init, }; +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(&sd_spi_info); + type_register_static(&emmc_info); } type_init(sd_register_types)