From nobody Mon Nov 25 03:30:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719506792; cv=none; d=zohomail.com; s=zohoarc; b=dcuK+SNwxnXCF4cGC6XvYpBp2XC08ohnt6+f1aerlA0aBXbb5TuZBfI0u6REPGZjbi8C63bVPh6EKcjThPm/iRJqJNNN/xQL/YTfYEg6EbCBlBo0/FnMXrMhVzyIXIkbU1SSJyZtDqZ9nAIu1IBrGNPm1Zml+bL9Nz1CAfjrxDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719506792; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=Kfh7nh7EBFUBtqV3Cc554QDUFLnqoBMYipZf+NIRV/K0G1irnenWg2VErc0FchxClrW9yltXUab46MUWtG8uFDADT5G3FckIZ4zxDSKj7fDko70RoCuCUyBvAHdlVFKCV4pMq89ho/hCHZak5NKUxUVPCcebsNrFeelJE5HK0E4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719506792919146.79851838006493; Thu, 27 Jun 2024 09:46:32 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IHyDP0ZOgwnbNPDUGbuOCUznyCdRSz3DIV5mdoYYKlGDE8tb5bLrQaeLh61iORQKFHHQ+3saA== 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) From: =?UTF-8?q?Philippe=20Mathieu-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?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719506793109100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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] =3D { [18] =3D "READ_MULTIPLE_BLOCK", [21] =3D "DPS_spec", - [24] =3D "WRITE_BLOCK", [25] =3D "WRITE_MULTIPLE_= BLOCK", + [25] =3D "WRITE_MULTIPLE_BL= OCK", [26] =3D "MANUF_RSVD", [27] =3D "PROGRAM_CSD", [28] =3D "SET_WRITE_PROT", [29] =3D "CLR_WRITE_PROT", [30] =3D "SEND_WRITE_PROT", @@ -1487,6 +1487,33 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState = *sd, SDRequest req) return sd_r1; } =20 +/* CMD24 */ +static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req) +{ + uint64_t addr; + + if (sd->state !=3D sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr =3D sd_req_get_address(sd, req); + if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, sd->blk_len)) { + return sd_r1; + } + + if (sd->size <=3D SDSC_MAX_CAPACITY) { + if (sd_wp_addr(sd, addr)) { + sd->card_status |=3D WP_VIOLATION; + } + } + if (sd->csd[14] & 0x30) { + sd->card_status |=3D WP_VIOLATION; + } + + sd->blk_written =3D 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; =20 /* Block write commands (Class 4) */ - case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - addr =3D 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 <=3D SDSC_MAX_CAPACITY) { - if (sd_wp_addr(sd, sd->data_start)) { - sd->card_status |=3D WP_VIOLATION; - } - } - if (sd->csd[14] & 0x30) { - sd->card_status |=3D WP_VIOLATION; - } - sd->blk_written =3D 0; - return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); - - default: - break; - } - break; - case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ addr =3D sd_req_get_address(sd, req); switch (sd->state) { @@ -2308,6 +2309,7 @@ static const SDProto sd_proto_spi =3D { [13] =3D {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] =3D {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] =3D {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOC= K}, + [24] =3D {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BL= OCK}, [34] =3D {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] =3D {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] =3D {10, sd_spi, "SEND_PSI", sd_cmd_optional}, @@ -2344,6 +2346,7 @@ static const SDProto sd_proto_sd =3D { [19] =3D {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLO= CK}, [20] =3D {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] =3D {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [24] =3D {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_B= LOCK}, [34] =3D {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] =3D {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] =3D {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, --=20 2.41.0