From nobody Sun Dec 29 01:46:50 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719559137; cv=none; d=zohomail.com; s=zohoarc; b=eludsdg72ri8bVi1eHSDw8S4aLw858gxLJ7rEiw2DCHLEhFyiKGNMdaMNtXHuX6enSH3BlWTsfFAqstJ46AOOOOp8QXxHeNg3upW2BbvWYohfZfmUuDIgTq9VrwuQGDG8vjN1bqvL1FHZziZM4heEuo93I3Nulhq2HB7dqAADAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719559137; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=TIi1dCnx5tUrLB39AREgGqMsx/uQErl4Ujl5MKTN4kkH+3T+XMJXS6hRZcxrssSV4CcbJy5/RuXEXeL9TXqY5p7F+EBcV2RRE/2PwYhNu9H/h9mEz2cMhrg46lf1CQibP5SAkMQHEQYmcw00s7Au+f+OSgUhxpimuOxkfGQVd/0= 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+importer2=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 1719559137589368.64618445308065; Fri, 28 Jun 2024 00:18:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN5iW-0004JN-DV; Fri, 28 Jun 2024 03:08:20 -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 1sN5iU-00043z-SZ for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:08:19 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5iS-0004Mr-HS for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:08:18 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-36743a79dceso862856f8f.0 for ; Fri, 28 Jun 2024 00:08:13 -0700 (PDT) Received: from m1x-phil.lan (cho94-h02-176-184-4-239.dsl.sta.abo.bbox.fr. [176.184.4.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a1030dfsm1320674f8f.100.2024.06.28.00.08.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558492; x=1720163292; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=yF1LgLycPUkPkjC23NTg/Kw3PQnWYW7TW+raxudZ1SYEGn3wNAaHEh+iFzV6R+vp+x /d7k2z/4tWfRycuc+RUO1B9xWQwkomNlMoSmKLX388yjf62H1Tcoq6Kzv1RbsE0b06n/ NOMWF1AN1LnBvds6W09cNDq/vzO5Ve3nXDpzIK4JjkT2MghI0SW93UXVHqBPm1tM9FEf n2ubpn1DL3M8z4aEMafVqGFjsweC/gdHHYvUHsyb8Aqk718CpbRtSTVgtIEDUvOGStUf 6PnCt3Uuz6HCzkDAtJnc/15fajsIpu+QOCjCtZL2ivkGKjsk9KUwEdg9WRMjCdIEziPT 1W0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558492; x=1720163292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QJ6b4+TolgSwbj9JxT9jbN1DwNz8KwrcgVlUMC5kG7c=; b=ZOe+ElfUa9dOqiCRicAEhJLIGSuXvL2Nw3wVhYF6aIOJcUeYNDMwhBkR2hspH5gVGC am0TcocrR2cmTLp3r/JjSxJTojARSN4OAmHdNauuPxcEVgteG1mDdT7KBfOVWFLv2njP 81nHlHav9vdFWWf5WWU1WIw25wkVyp0tGNL0gJhxKPtLzn3Pxq9ZPVpLkFoJUiJYbVGE dnZzDNiBGkXKEiHe84IQFnHCcuf0daqyjrBfA81gj+vJ1MLPNHFuRI7tRJHnjkqrixr4 76qZoWGqn9iDcl/DrjyytIU4lw/ugR51dGCgGgINQ3Qni49AgBufYl/KmBQvUh7RRp7Y fDCQ== X-Gm-Message-State: AOJu0YzI70EZXu7r21rOPHvYAh7lN8zWXWpTpCX6L6HrJf/orSC4J5tp haRNxl3HmrsRNtemcekVzG+fN8jzWp/5UXx6anSkcg4REttM0gGaYJgGmKcKWDGJ2xWQtJy46Yt rHIc= X-Google-Smtp-Source: AGHT+IE2YnA9q7Pd8hbEuqa1S2LVxssZOxGpDGXypgbY/Lcv710m/dhLwKvKy4MydWO/B1KOh0celg== X-Received: by 2002:a5d:554b:0:b0:366:ee81:b87c with SMTP id ffacd0b85a97d-36760a7dd7cmr624079f8f.15.1719558492192; Fri, 28 Jun 2024 00:08:12 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v42 57/98] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24) Date: Fri, 28 Jun 2024 09:01:33 +0200 Message-ID: <20240628070216.92609-58-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628070216.92609-1-philmd@linaro.org> References: <20240628070216.92609-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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, SPF_PASS=-0.001 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719559138616100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater --- 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