From patchwork Thu Jun 27 16:43: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: 807866 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp899580wrn; Thu, 27 Jun 2024 09:46:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUJsu+I8Ik0o/AFbaHFf5mqqFTTOaHdnK6w5E+QeP7zGRhXmKhiBBfdudry5TFs9hQgpWlcUhP0gJiwbpceyRur X-Google-Smtp-Source: AGHT+IF/EzPP/otA6Y4IMDQc5A0fqQR2PctyJ8X9ez+bGmRrSi+oAu5aUECUg3rqo+o/zuauW3DP X-Received: by 2002:a05:6102:34c:b0:48d:b0c5:7fe4 with SMTP id ada2fe7eead31-48f52be702bmr12201463137.29.1719506792638; Thu, 27 Jun 2024 09:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506792; cv=none; d=google.com; s=arc-20160816; b=JArGQOGA8wfqnRyRedPmLIS+rAwwWCGBEDTbKj/B6ZkppWeggA8HicbrvycmMecP1O HPnQImHBOFQSZD4Hd5mz+nz2TyHaOLdDi0bJFQWGviRSGXm+VMs7VVHRd/4RLzEAryse Suw+NQ/f/zCjCoVMulprGCjFt8dTTRNq1OM6fnVCjscX6UV0wjAjHh+BgR7vzS4WkBv1 eVB0oWcEb4WXJZJFKw6XQE9gww3RezpEuuPSCdsamf79pJPYhXXRRebNljDwkpxhOXaz bYuh8dL3qQx7aMBmjKg9gqKlF1h1u++TNmjm3wO1SJRsLLfx+aG2X8mTdPJn/ruJ/+Kp Xi2g== 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=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; fh=v4x9Oqm5dSIIGNwhX3iTRsusFrFNP2dDaR6uZLPgHBY=; b=lIDGSiFWX/bid1nHa7cQK5RYHqNlej4RoN1FFbIJ1Sb2yeQhtAkZ9wMzSBV4brrW7r W53xeso7R5n3C5EPMPPEWT9cdcEAWxUjZ7OJiQm4WxOt4Sn9Wm0GWwWy10YGMvXcTl8L Mg9c1Y5p1sEb1SspHVDRwtMaKmc886U1mrO4VrtlOJP0wlI4/cI4Xmb2iLUp2j0LXjRM K7ciqtci9MuZ1dtLhw2qyyjgNOnXnjCyA7nyIBNXq8zN0yP4+hce8LeraMmqscZZ88e6 1KeTWefyoBy3zHcqLJu3hZ0YfACeOmQKn2f0N1PZwy0mkikgPDih6BZ/y3AyEY9oNiO+ RWBQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qml8qiv0; 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 ada2fe7eead31-48f8e5da5e3si251876137.831.2024.06.27.09.46.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:46:32 -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=qml8qiv0; 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 1sMsGF-0005jZ-LX; Thu, 27 Jun 2024 12:46:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sMsFv-0005Wu-Ci for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:46:02 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMsFf-0000B2-6o for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:45:50 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-421f4d1c057so63900445e9.3 for ; Thu, 27 Jun 2024 09:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506737; x=1720111537; 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=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=qml8qiv0FaaoRFxhaHOPfjCs8c7hMvMgh8BCXEwbH2+gs3ruLjs985tRO+sTUzeKVq GWO9o4z01xTrF6bvx6Tqozcsy4TaaNEtqHmNhEp9pv3rXssJ98b5OqnXlbR0ZYnHCaTv PUel36uzmNFDS3EPRLuazL2+ZaZ5djuSiOD9cbGZ86xchwHR3dsnr1YygOjM6LnB27dq t6l5NXUYaGGUBQmov4trMtrFI3ZA+YW5aJT/ITxvngE8Gtk+vqn8MK33ndoAR0fJ6763 pC65MTkfS5NtYQp9y7NELNYSf2BBntBvGadISXKyUpUOgtWqGaFINY4HsPfL2OpHAE8Z /0lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506737; x=1720111537; 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=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=n1iQC0hnPeyCDC3lhDzVUp4cb+OdVtXK3msD1iqsvgVLfvYbYrgHToIT4b9Ybobu3N LRFQLcVHZqGrrROmZ87gkR2B+k9EW+AuHgki5QZVvG+qx+DaPHRaephsC3mwpo9Sbpxl pYKtKzECe8eJV96KG/DYuW84D4fIAAPs1IqY8AK5ckz/dGmy1jafwKuxWl/6W8y7VSdr 8ucQGYRk4Sz7bzWklTh2wc8OsTHbMjNAG0PxDvTCsbymb9cwpi9oLhfzTor4JwGiMP3T 6SkceEKut3Q8gUoVP4hU5qjfKx3AZS5dZSsVGVBQmvk0iMRzGHsQS2gfhIBRlpKQGGnN 1xeQ== X-Gm-Message-State: AOJu0Yz2x2MpPPv7zOH7rj4NFJU/wmw8vAlIVj0XQmLvSqc9EY5GOCz+ /xFT/f5FvzFlg5SsH/efhf08zwndmwpEhUhNjUG/DU1D48AB7H6Odg4aCWR7U3n77xiXafrNfzn tdv4= X-Received: by 2002:a05:600c:2e4a:b0:425:5e9a:5958 with SMTP id 5b1f17b1804b1-4255e9a59b3mr38061485e9.22.1719506737617; Thu, 27 Jun 2024 09:45:37 -0700 (PDT) Received: from localhost.localdomain (33.red-95-127-46.staticip.rima-tde.net. [95.127.46.33]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424c837dc4csm73263165e9.26.2024.06.27.09.45.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:45:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Sai Pavan Boddu , Francisco Iglesias , Joel Stanley , Luc Michel , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH 11/21] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24) Date: Thu, 27 Jun 2024 18:43:34 +0200 Message-ID: <20240627164345.82192-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627164345.82192-1-philmd@linaro.org> References: <20240627164345.82192-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=philmd@linaro.org; helo=mail-wm1-x32c.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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é --- 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 e2a7ed8b45..4650d20ee7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -242,7 +242,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", @@ -1487,6 +1487,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; @@ -1544,32 +1571,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) { @@ -2308,6 +2309,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}, @@ -2344,6 +2346,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},