From patchwork Tue Jul 2 09:20:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 809107 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp118933wru; Tue, 2 Jul 2024 02:31:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUCTGsLHiR78pVXZVT9ENMg5FoGnqBkojPek6/xVJsB/+sS+F0/yDLpxmOygzfjfU8mJFOfGE6uKVzVVCHl9dgB X-Google-Smtp-Source: AGHT+IFO74VXCvTHMm8PFP2wxRzFBWpdpQ4U+DuvelzljPrBAH1F6NyXgLxNKDu02LGYJq+v68ca X-Received: by 2002:a05:620a:c0d:b0:79d:5c31:718c with SMTP id af79cd13be357-79d7b9d4012mr825975285a.27.1719912691205; Tue, 02 Jul 2024 02:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719912691; cv=none; d=google.com; s=arc-20160816; b=wTQ6qXWbK3KdSrWbYXYfxNnFBqk33D2XGrEhOW16I0+KzZHJpoJ6gAtPbWWsTuZoNr qoW3mAxpUwsvdMdTE3+eitso5Xjx3fLkoS6jpuD/NgQWfQMr9rB+EajYcqb6k25BS+Ts k/2SxTY1xyCkxSm4WfwTclE++YFf4HMPw9jj6Sw6G3n0GMyLJb28tV92RG2VLuM0u3e8 CdG6/S9cja/fdQRzocaMRoPdIh6+8s0usjI7F0fVcFmVnQMnlFgZ+akD+VJGZS9Pk4rN 08SJjFsRl/6LmLoARuMCtanuCMGOLCaik89dTWUeM+dEbJpJUm5cXUrMIVNexUad4VOI s2iA== 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:dkim-signature; bh=MYL5paPpv6jEUEf+c2iXnwTu+YdBcD9M6q75+huuwI4=; fh=/TyiCVzPJVYkT4NtrOYZRXAcrkaiLXA/rwqp4QqIc5M=; b=NpadpV1J31U2/wRUkvs9PldaIOo9C1eiAKufVOZLhx1pp00pqPomyp9/BOolAifyIW xafJo/WPQy9YryCPId6VfkKkDPSh8j+gSOMctcLUw9ogVHfWmBnboAFowRccICYjKikn VKMMeiGDPoN3nbj5hV/TTIdAvEVAB12ouFCQCAmz8/lyfOxNTSZuUX0H2GJ8GvEW91Jy okQHLKSPFwh7f/8aGfVXH50MK98h40YbLLFHn3rvy+o7kbsaV7Rsq9VV1/MGnAHlK0SW YMJLzevGPGZHYwt+qxXx/uycg7JhdSqbzCR0qZKnpXDsaaiuAeHjG4ksUfTxp6XmUuWh fXZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MIRVXuV2; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79d7334a6f8si960650385a.563.2024.07.02.02.31.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 02:31:31 -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; dkim=pass header.i=@linaro.org header.s=google header.b=MIRVXuV2; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZm6-0000QX-LA; Tue, 02 Jul 2024 05:26:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOZly-0008Pq-Sl for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:02 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZls-00012E-T8 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:02 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4257a390a4eso19067455e9.0 for ; Tue, 02 Jul 2024 02:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912355; x=1720517155; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MYL5paPpv6jEUEf+c2iXnwTu+YdBcD9M6q75+huuwI4=; b=MIRVXuV2oDuI7C7/1sEZ4LpEVjW+vzM0VWG7hLKSNPru1P9sFvxorYvODxDOJ3YcHv lXdWek3OsqNNmwk57dBrVCc/R1EO6nb/56F0JVWGe9FIVQ9qaTSTnMfOu9Gmkupa0WCk thM04EwjWkZfB56GmuuSBs3qGiGIKR8K1T4GhXk0WDLpcfqi+tYv0Vg+uVZcbZkkAgbb /oVlS02gVtx6TPhccGyxkBmuRUSet8sbggfI8VB2P3NsbKWwqHLd3WyOQLfgUXCmHg/Z +Eep+If+S+fMkqar8O8sabtN37NbxsJcA5Rniv1N58rV22v37Si4mryjgZugbTFckrsu zAIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912355; x=1720517155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MYL5paPpv6jEUEf+c2iXnwTu+YdBcD9M6q75+huuwI4=; b=wuJAB4BsPwNujAAmZfbzoR8u/1rJpl014V+UBwHhRC9eWr0Qaqkj6vEPCjsc53865L nSU/zHQ5N1aXqO+JY2rUa3ztntLFyQbwwLI7xC6D3Wo/w7pWtGU5dDnSDhSj2xRPL2SW 5PuShWEeuLnpdhgFX7CB1M3DWLnLHc4wkgo+PvOpi/4ViqRJq3Bfu9O86ZL82bO+EciK TdwTM3jVYOhbMBaBakgMYSE/9hHpvwUF+SyafMO5N7aFIXnf/4YjzdH2dnjR6zxBEWCg Gow51PuA3AIr/bGzmlBkezz4jvn6r4IgwOr60tM8cvHE+gDnEld76gYiSRzTcCKzI7S8 xREQ== X-Gm-Message-State: AOJu0YytC9oq9L/bH4EiondWUCjb75l/DfNptyR+ThfLPY7LaUXJ6S5E wa2joIkTtP/b84PYD7BC6bnP/1XR614cNN6fI8SuSenbphGMfbkAIsY5emItzF7BY9Uo8dIPMTh r X-Received: by 2002:a7b:cbd2:0:b0:425:5eec:d261 with SMTP id 5b1f17b1804b1-4257a02805dmr62785395e9.34.1719912354928; Tue, 02 Jul 2024 02:25:54 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e1430sm12682288f8f.52.2024.07.02.02.25.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 51/67] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24) Date: Tue, 2 Jul 2024 11:20:34 +0200 Message-ID: <20240702092051.45754-52-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=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 Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-58-philmd@linaro.org> --- hw/sd/sd.c | 57 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3f5cc0c55c..02a1203691 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -239,7 +239,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) static const char *cmd_abbrev[SDMMC_CMD_MAX] = { [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", - [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", + [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", @@ -1479,6 +1479,33 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) return sd_r1; } +/* CMD24 */ +static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req) +{ + uint64_t addr; + + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr = sd_req_get_address(sd, req); + if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, sd->blk_len)) { + return sd_r1; + } + + if (sd->size <= SDSC_MAX_CAPACITY) { + if (sd_wp_addr(sd, addr)) { + sd->card_status |= WP_VIOLATION; + } + } + if (sd->csd[14] & 0x30) { + sd->card_status |= WP_VIOLATION; + } + + sd->blk_written = 0; + return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1536,32 +1563,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; /* Block write commands (Class 4) */ - case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - - if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, - sd->blk_len)) { - return sd_r1; - } - - if (sd->size <= SDSC_MAX_CAPACITY) { - if (sd_wp_addr(sd, sd->data_start)) { - sd->card_status |= WP_VIOLATION; - } - } - if (sd->csd[14] & 0x30) { - sd->card_status |= WP_VIOLATION; - } - sd->blk_written = 0; - return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); - - default: - break; - } - break; - case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { @@ -2310,6 +2311,7 @@ static const SDProto sd_proto_spi = { [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, @@ -2346,6 +2348,7 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},