From patchwork Tue Jun 25 07:34:35 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: 807265 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222694wrt; Tue, 25 Jun 2024 00:36:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWwTgTbDMa19wJ6QsMGHaSza+vH23XbRlZbgk1RJn+G8AhKDSfG+PmHz4S9136FAyTsW8wFGmHMKq5DNZFZMBPf X-Google-Smtp-Source: AGHT+IGgUFj/JSYf8ouSEVrEd9A1hlKzbZPcn5TbTFY8zox4bU5NnnHpH8czwvv+f9NMRnRsAgJ1 X-Received: by 2002:a05:622a:1906:b0:441:5642:aaec with SMTP id d75a77b69052e-444d921a742mr80871271cf.26.1719300969581; Tue, 25 Jun 2024 00:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300969; cv=none; d=google.com; s=arc-20160816; b=YaQbMZ5I3fQ3Z1KDjFy4wtCPo6CE0t9PPu2TkofWjfwWVYgI4D4ayXKiP0DQlvTlej vEM5XzFUDXZ5aERUZPUJtKiScJH5UZR8vwNQwNOmgufIcF7AEp2FVZn0CRRVQ/pX6Fsd xPVTTstfRmV7aSqzkNOPoLPT7qJoMH+3eLe7D0h3mBRmBC3kF2OsEDdn0Ki+52MJKiRH /4UDHpqlY9CJ1hwpkG01X8qosTbDq+JI3INd/UJZlRVqvS8UOuaJKphBD0BN687Olh48 mECVToYU6S3xQIJPfcpBrVJ890AqtGdC9Kk/AK22wSr1/H679UrE/WzlkVz7N2T0Oq5Y C8IQ== 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=wcx7yYRM3PiZ4d5mUpewwCNROsxhQ8qYk6qnzFU22vI=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=XQqlfSHbYU00vMNgLmjlpSFGs7GfEzRt/VQf2kd+3+hqxK82xKIVOB6YfvpFRA3Rlh mqJrZnG5GgOgYIN2uwK8VTBuj2fEn412iq15dUeWqdkkV5kcCSK41HLn2b16TpVIzDwo c2+CVJXqlik4RuabzgkKH3bT6gxanVvwr1MGhVhjuuJsu96nv7n3n8imZCKYeeODDUDi fdtJuCcmgEbtNv74H+OXsGzMKgi4gGHYvjoaDOY0QUvyQPf874xnfyynLn1N8bcctITD sOgNvY8oEoHyCsoZG2qe1hp2NUYHTfQTdGr0emHNgMRU3UqPMSHSTbqFKgANwZTwtIe9 z/fQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VIVVz+6t; 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 d75a77b69052e-444d99b4eddsi57791531cf.74.2024.06.25.00.36.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:36: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; dkim=pass header.i=@linaro.org header.s=google header.b=VIVVz+6t; 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 1sM0hb-0004W1-Fm; Tue, 25 Jun 2024 03:34:55 -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 1sM0hZ-0004Sx-GY for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:53 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hX-0003kM-TZ for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:53 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4248ff53f04so13660965e9.0 for ; Tue, 25 Jun 2024 00:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300890; x=1719905690; 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=wcx7yYRM3PiZ4d5mUpewwCNROsxhQ8qYk6qnzFU22vI=; b=VIVVz+6tah2WqfeqZ2rlKCJZf85jNV5owBvqisWraic+RVlJg1sfSp3v2y8NAw42VR BNSX8aqvL4CLAxnQW2jPzTE3K7hThUdZClksvgN/OhOFevVdPS2KAkmqarNtGcMlrWQi x1C9A+MzPSzGSNfxs3wohWKSWtrplF4jcj8BIigDUHwrH6l9UJKCUcmV4Gk0AGXDd2Ii +1krkDEEEB99JhJtIedTBYaF56TWrRNOeEwdSo1MXGVTP1O3I+kz1ewmFxqWkr0OFVOq RmUuCmxNwLBLIl+G6vIZVcioxTot1uMU6gPOSEf36HrsQc2+KohZW2QmYIvwN2kb5EdK 2MLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300890; x=1719905690; 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=wcx7yYRM3PiZ4d5mUpewwCNROsxhQ8qYk6qnzFU22vI=; b=ffNvHdRhGmX72tuLka8cluQ+kRAe+eTyaHrE0uz/dvc30zfPD3bKt6GnWNxiByuR7I bgeuPaPhspNgJnP4mh9xV1idP7JWwQrl0uIsBlarR5WVTef62fheNNn3BnNBt7bnVLPd 36b5WX3XbZ/feVfbw7TreGvK4bLtkoHh57+m4XoAY6avzRpyDpE+xf7fVseAX4NpyqwE QrKFW7GTT2zFpz59pIjE3RxqU7ygCmQZ9krm8F1f55Flf/t9KaN82MAB2Tlrmj2vviPf xS9q5z6ffdcYD6uZr+2gI0O13rt6RoMQQmj2lMTzegMfPoaFppDU663drW3AFsrp9IZK 2qhw== X-Gm-Message-State: AOJu0YyaOOFWv+PWQaU+r2l/Takxz6bmeoIx6oPfW6HaImQ4oDnUo8Xh CBYcicWxzo0CcfB8jjuO8WlqnI1hwTlrflryd41TujySonpp+Adbt2pI9cmmS5uznwC+Qgrjaio + X-Received: by 2002:a1c:7711:0:b0:424:816e:872d with SMTP id 5b1f17b1804b1-4248b95c94emr50128615e9.9.1719300889916; Tue, 25 Jun 2024 00:34:49 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208b3dsm204176865e9.34.2024.06.25.00.34.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:34:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 1/7] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte Date: Tue, 25 Jun 2024 09:34:35 +0200 Message-ID: <20240625073441.34203-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org All commands switching from TRANSFER state to (receiving)DATA do the same: receive stream of data from the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers: - sd_cmd_to_receivingdata() on the I/O line setup the data to be received on the data[] buffer, - sd_generic_write_byte() on the DAT lines to push the data. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2df3c28cb7..7fea0afb62 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1081,6 +1081,21 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, + uint64_t start, size_t size) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd->state = sd_receivingdata_state; + sd->data_start = start; + sd->data_offset = 0; + /* sd->data[] used as receive buffer */ + sd->data_size = size ?: sizeof(sd->data); + return sd_r1; +} + static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start, const void *data, size_t size) @@ -1930,6 +1945,19 @@ send_response: return rsplen; } +/* Return true when buffer consumed */ +__attribute__((unused)) +static bool sd_generic_write_byte(SDState *sd, uint8_t value) +{ + sd->data[sd->data_offset] = value; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + return false; +} + /* Return true when buffer consumed */ static bool sd_generic_read_byte(SDState *sd, uint8_t *value) { From patchwork Tue Jun 25 07:34:36 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: 807266 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222695wrt; Tue, 25 Jun 2024 00:36:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWrg3luRgCbYpAyf6N3Lf5X9658v/J1k3R4xZXKpomM9Bcr3KyJR/+xyDePhA95pydUwUDze1qJnmL+kkjdsO+R X-Google-Smtp-Source: AGHT+IEk0/hbjelc/rWUJQ6DYU5hJcb6o8lqzUwib18nFGhpstlxUYjNwq8aQXYAI5iI3mWvNGNO X-Received: by 2002:ac8:7f02:0:b0:444:d2d0:9a52 with SMTP id d75a77b69052e-444f8a32740mr5794361cf.35.1719300969595; Tue, 25 Jun 2024 00:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300969; cv=none; d=google.com; s=arc-20160816; b=CUMPKiSf3xoBYIenS/cYc1q4wztACnKDR/6OsBU1SsrUsirc4W4fPB+182dCG9QmPg 4q90/2lWCa/rvHVc2EmpbdiiVG3RlbcTIOPt4F8Txnk9+PbviHdGBJzHEM/cjVhnPdfz 0weSVkS8PJ16xk4P1/2hSQrmjkE68x5UMuJCpowUPTixwAkw3mPu5Rql7A35YPUmBxbP ZVDQE9i3Ca66qF+b9TKpnUi0arST96d+MFbvVKGILzozv0I8WGtY+C4uc7f8daNyW9K4 PiSGLof3XNhH3jgKPiXnoQAq1UH+FH89Pr5kfdVWXtx4my5WQOyljoeczB8gwDfu+eia 2iHg== 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=MFRKHAqO647KOdwqqDJufJ/DZoqjTVohRrJvslLGVMw=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=HJMCND8rwrnoyxQ1ctlIYhAlqeemaxI0tVJDQOvAjjF+rHzFHKzmyoakMfzKY7v084 CPodxXtT8rN5rLbNq3pRtw2yGpLmWC8CR4bS8AxcuCEcdwk8RzJJwAkxaiKJemuYa21P aSSvxU9iEvUwqPXeQ0FQolB3CzUBW711kms7ZreV1snkZe6EuiLo9WrcjTaSCYCPJoZy 911oTY0/UkfrwNy+lcacOqPijqfytI8+BQ79UqNgW2xpJII/qsdVTRZNFUZLmObUYp6C iPcg/WVU4NyR1Z/dvAwEOvOR7W3CcXDvGCDR7COWVl7T4/3nEpjms9tW3FLQmAzKi7t6 57sg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JaFdkVuN; 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 d75a77b69052e-444f07e63c8si17259071cf.309.2024.06.25.00.36.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:36: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; dkim=pass header.i=@linaro.org header.s=google header.b=JaFdkVuN; 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 1sM0hh-0004XB-71; Tue, 25 Jun 2024 03:35: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 1sM0hf-0004Wp-Jm for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:59 -0400 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hd-0003kj-V1 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:59 -0400 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2eaa89464a3so60313641fa.3 for ; Tue, 25 Jun 2024 00:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300896; x=1719905696; 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=MFRKHAqO647KOdwqqDJufJ/DZoqjTVohRrJvslLGVMw=; b=JaFdkVuNjkwxcVhuSofUzbSLP6bLTa8eUJp3tAzdIHzh7VjidthKPCzWVYLr+ACLGt jvEWyLVon0Bb20iCgH20QYWuX0pzvcS67tg4tIh1cjQIXSD/+oof2q4u1qKEnBCm1V6Q vip0msazKJBcfJYLbc84wJdbZhJUCILy8elPALQ3SLnQ0EPJRnLWlULIrFUukfaN+dVG og2kDzyRGfuH+zUVu9I4NpDMN3Ix9k4/VaBhAFVHaJen/hBvnla2d+/S4gUA0xEjWxzl mY+y9Y3Rro0IkTmhZC/y+iJ0G1yTueyrc2o42zrzKUwwfy2l/bUOVdS9Gyj4pGQVVaS0 gurw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300896; x=1719905696; 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=MFRKHAqO647KOdwqqDJufJ/DZoqjTVohRrJvslLGVMw=; b=KQ4dqdaoeyy+B8aMfSX/LgShTDKjvu5LCcDinoce3eGMXY4O7IF+n78aiYWEVefBIv 1xPlQmqjgS5D2KNKOWK7QaxzRo2uAgoz/bdl/myNaUZNCgubcoDQJsVVuL3+fFMr4uGF EQnCrWdk0TaPBXMs9He2DGCPhfCnzwQYA99HGv+fMifp3hz0ZpdFzb+yX+x7y1agfX7y 4RULhMVAvo08JIaHMKynmoQ/qXeIjTgcB+qBdSzKE2N4m6mtiGz5gfF8pbCPoBcqwxZk rzrt/HfUobZR3wOLHL3LflyZyjNhpXxnTcrAsQdjY2+sB7Nday7Elg+tE1TaU/7TArIE E3hg== X-Gm-Message-State: AOJu0YwQtvBqVkyPrnD4kbcOKUY4vIKTjuZKlnEp5KKvxGqP9D0nqWLL f3p59Tyvcs70Q6ubdCv89D+WrunZcyvpQ8vfuYf5hg5Yf2ipXcTWRww9cEdlx6tHmpJEuKb1W1y E X-Received: by 2002:a2e:8617:0:b0:2ec:561d:dee1 with SMTP id 38308e7fff4ca-2ec57967b7fmr46632371fa.8.1719300895562; Tue, 25 Jun 2024 00:34:55 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0be818sm200163415e9.15.2024.06.25.00.34.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:34:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 2/7] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases Date: Tue, 25 Jun 2024 09:34:36 +0200 Message-ID: <20240625073441.34203-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=philmd@linaro.org; helo=mail-lj1-x231.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=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 In order to modify the WRITE_SINGLE_BLOCK case in the next commit, duplicate it first. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7fea0afb62..8c30826754 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1437,6 +1437,35 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* 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; + } + + sd->state = sd_receivingdata_state; + sd->data_start = addr; + sd->data_offset = 0; + + 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_r1; + + default: + break; + } + break; + case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { From patchwork Tue Jun 25 07:34:37 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: 807269 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222836wrt; Tue, 25 Jun 2024 00:36:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUzi1UebHfu0mNLaj5Fidw61NAUsRqq85/Fu0f4I1DZKIGO9rVqIkleicMom2R2J6eFOjbaV0jkQbsZ4y2WDkSi X-Google-Smtp-Source: AGHT+IGgU36EkN0SvNlxD4Luwmg3A13DCiAkFOkHTywiNEMOHZy98hVMK8Lxi+Qsp/zb5yiMEqcT X-Received: by 2002:a05:622a:1b86:b0:441:5887:a04d with SMTP id d75a77b69052e-444d6441a2fmr65187591cf.11.1719300997709; Tue, 25 Jun 2024 00:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300997; cv=none; d=google.com; s=arc-20160816; b=dwqFXNHooK7DaePhtyXjbUyBIa0WE+p/SlsgZ42YV3nI/hE6CwHTQzFXMoY73BFhbN jJ2T1PH7CEziZFeLpc17f5QLsgY1HQTq6WkYmGYmdnaM5HZ7RyNXNXkhbglXT93423J2 Bbt/OjSP2K5i6PLtA+dAyLUvCr3tv7CQss6dJKJI6bfjbCJWHHSF0UwY0aqTRBb6wphd KEcBE0KGgRfo77+GQUG6L369s/gsjRlgJQ9/X/nN0O5wbyBlHzjOQ9P8Mk4MDAa3vLCC lUOPv9kFaRAn7cjKEbkJqjjBtwiYSIG+7x8q/ROusOaQrogCm6/8HRZ4vCVdIgsvhJqd /YgA== 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=wK0X2J7xkzuOoEV+SXxI0L9Mdx2I1sNaqE4cl4V+Wxc=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=JTU37w8ckveZyBC+QcjyPkFMhlSxMcN+MqNavFc80M4fpciX7C/vzWXRcf185n/Jpo 2ww3ilMQigFF3fuxVYTBoqs/VFcqngzVq4tByqhGRBcvOyJHUoxog50wCaN3nHwD+5OY mgZG2+Xztggo2mJtxYwj9FWxIcNHRZXGXXIXqnUHzzU2K9NHp789U7IZpZ3ablig/tWF arqSFzooJ26S1B+7USBIzJi3vTfgyKcCw+64gInjJDXbAZrKGC0EI45BRbVYKAwHxED7 0cTuE/+R2eSwUQ99Tf+Jiyk46fnCdklYWpVPXgxai0vi4XjfJagb8qDJ8JRCK2K+zHzo plFw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M54iHxNN; 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 d75a77b69052e-444c2b4c977si96703151cf.6.2024.06.25.00.36.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:36:37 -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=M54iHxNN; 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 1sM0ho-0004bX-7Z; Tue, 25 Jun 2024 03:35:08 -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 1sM0hl-0004ap-8h for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:05 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hj-0003lI-G8 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:04 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ebed33cb65so57158391fa.2 for ; Tue, 25 Jun 2024 00:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300901; x=1719905701; 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=wK0X2J7xkzuOoEV+SXxI0L9Mdx2I1sNaqE4cl4V+Wxc=; b=M54iHxNN8SiAkNkVpD+eR/6SRzLjI7VrrwRmAlnkT8lvXMnJA3vEAJrOcXbOEDBSnZ xXo0fzjYLS8Dvcyp8HECvlUdIFhsVtw8Z9Ynf1ouwLrXkuQCN69Zxzls/dFBiNyJsXrI bF//SXHnZjSWBV16eYWmXD7b61PTlSXEAbmV/ZhnwfcG8yPeL6kjsKnIUwtWRlrC/PSu 5/cF8DVqzKUremXGJsuXUZKdhyRc8SgKpTnqiu95SfYpgr4V981BiQqPemQuO/9bqrlN 7vTz960Z9ge4jLneELiIKsZXLzMRHZRb2py3neIPOteD4A5Eu56k2Wifsq/TDQWV/kFr qgQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300901; x=1719905701; 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=wK0X2J7xkzuOoEV+SXxI0L9Mdx2I1sNaqE4cl4V+Wxc=; b=D/veaiJVlIfdtUZRynHXt7y0XUAREuEp3uugzTCaNri5zkso+iNmUa2QR21pRwAYp7 phArVbRYuuMthrzboJnzaHgxPeYuRG8+V6hWiJkjiMESf/OEaSXT53smWc/LIIthaD8x ysSvIpijoW2XobeldR8aoTuC5GonqfV46nvg/pyQraC6KQZkhiQ6d/vPe8uxHSynNeeZ S1AYXXBJpAqapMl0RVyqjh5rKc3efcBQ6Uh5KgXlmontEl8Gnm4MH0Nyaixz/i3e4E4y YVk5NrF9yYkxbDcN3ED/LqZa3K5JMU2c8/pNL0NHpJ++UezYJNA1RGgu+TW7cTLfyT97 cHaA== X-Gm-Message-State: AOJu0YxrC1MnOqL3FRbKzANBarIr5CNCQH1qpbf4N58xKuojPq0qiIzc acLmCR06McneRCrM/q+eVjUcehBssnw9RHEzkN7deEx6+4i+H+yOPFQQljlYaU4Dvgn5mjkxPH/ E X-Received: by 2002:a2e:9859:0:b0:2eb:f0ed:a36d with SMTP id 38308e7fff4ca-2ec5931d44cmr56284711fa.19.1719300901360; Tue, 25 Jun 2024 00:35:01 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4249e48ad3dsm12591665e9.16.2024.06.25.00.35.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:00 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 3/7] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24) Date: Tue, 25 Jun 2024 09:34:37 +0200 Message-ID: <20240625073441.34203-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=philmd@linaro.org; helo=mail-lj1-x22c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8c30826754..fff4be3ae2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1081,7 +1081,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } -__attribute__((unused)) static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, uint64_t start, size_t size) { @@ -1446,10 +1445,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_r1; } - sd->state = sd_receivingdata_state; - sd->data_start = addr; - sd->data_offset = 0; - if (sd->size <= SDSC_MAX_CAPACITY) { if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; @@ -1459,7 +1454,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->card_status |= WP_VIOLATION; } sd->blk_written = 0; - return sd_r1; + return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); default: break; @@ -1975,7 +1970,6 @@ send_response: } /* Return true when buffer consumed */ -__attribute__((unused)) static bool sd_generic_write_byte(SDState *sd, uint8_t value) { sd->data[sd->data_offset] = value; @@ -2021,8 +2015,7 @@ void sd_write_byte(SDState *sd, uint8_t value) sd->current_cmd, sd->data_offset, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; sd_blk_write(sd, sd->data_start, sd->data_offset); From patchwork Tue Jun 25 07:34:38 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: 807268 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222799wrt; Tue, 25 Jun 2024 00:36:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU/+68SqIPhxZJIb6FWWJR/Z27o7t3hKkRkkVIZX1hlEnQJUyb89qgT2urWijIrMfMOQcqlp5ND6M8fxoVI2eAF X-Google-Smtp-Source: AGHT+IF8L5UB8xXML35elypcgpsWKipraufLOwPp/qOinhxg4s5r/1aBq+Twwo70Nn5CvXq/U85+ X-Received: by 2002:a05:6808:2109:b0:3d2:4793:9872 with SMTP id 5614622812f47-3d543b84f44mr8419545b6e.50.1719300991003; Tue, 25 Jun 2024 00:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300990; cv=none; d=google.com; s=arc-20160816; b=pblskMz/f2Jd/Zoct3KQ7fFbW0oKUFHDVT1iYLVFNnVSgwicJitCQO85ayZQVqJay7 cX1V8FA9mnvVpcDZdsyI09rpb0v3k+U7BhmB4rW/k2T7kmzTuJhZNCLKZVLCiR1wxb1b vC1svGHCTJttg4tjvk+rYNqDKn40vaKE8UgZg2LmH+m48hwS71JgyoKgpJg9KDRBIxgH B56H9Mx8WTNxEZbDviTUggAbELcnHpx7WNs+7xACtZiQPqz1A7QCeM/OetNIn8qD+Ybj B7I5WLxcy3aQdc84al/bJ16vOoYTMJ1+SvYsU3w8o6C0LihLtHIkDW9v9gt5ROtiHWSB AuJw== 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=VA5f/N1mW7Z/7ENwZP3WQRg2cxqQYBPog8kTusH9efU=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=QpByhK5ncaP3bydTP2lhkkY/PgSCcSMmH4cg1IcLP1yygN0+lJNLboLCSj4shR60F9 6591y4+d7B8Hb7tchNxpljTDt0RlbkWFx/OoBOSMdVqcz5WC9oweCCa2vp1Si2DBVND5 xVLxR2qUoMgdZ7l7aSVBlsSDB6sMJcHXP7YU1dwRVehO2MJGqkn/IvBAO2JQPlC3kb3z q2vNVeXyAq/OyIq4++1aOufjNZQRf+Pv3fNBm5hR7NBH90OQUvbbHdpN4qjoyHPKaRn7 UUoOeyXxV6j9pvyGlyCCSQKYf9z0tInBbKmkMPfOC+l+YmxN1sKVJ5iGT6XcgliQ/CGs zMYw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GbyCTq02; 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-79bce9148ebsi1037361985a.309.2024.06.25.00.36.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:36:30 -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=GbyCTq02; 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 1sM0hr-0004dE-PT; Tue, 25 Jun 2024 03:35:11 -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 1sM0hq-0004cz-NN for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:10 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hp-0003xt-7w for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:10 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3627ef1fc07so3909790f8f.3 for ; Tue, 25 Jun 2024 00:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300907; x=1719905707; 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=VA5f/N1mW7Z/7ENwZP3WQRg2cxqQYBPog8kTusH9efU=; b=GbyCTq02YFrWzrmaf6cniUn+zZ6b3uaVHqN0CzkVeHUEQCs7Jx8JTVfM663+Xa67n6 Wj0BHkPR2d3ypVu81lsh0hdeTY+w2LS+8/EcorXqwOjG8q9A6cgNnfZYisoNqJCU5ra2 MalYVqBwL4A0NkeH4acjDt9ggvg45A0ZUbm1C0XQUXOVsazFERXhKdJNlCUJo1qMhO5/ SGyTab+v4AE18q84pjFXpcmA4TzTpKkF678rom0xrv1sYBbN3DpCluml9hczICvVn0gF sZceInfL3UWWzOZP8ujD9BvqYd+uK2klk6vAVa/CPWlydW/4H6YOkDTZmIAZNkxzVt+h JEmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300907; x=1719905707; 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=VA5f/N1mW7Z/7ENwZP3WQRg2cxqQYBPog8kTusH9efU=; b=tKAbTMW2vpGlDREVO82nVBKEnSgi4mzK3RD5JLVuOwLfSHRUThvxgWaDgxSqDUgJOf JNmFPkcVIc1fn9XPPzP42AMdKowKvpC9z6Bd0KBUAk58AihzpQrg5EYAm1i1LvUfmiVs BmavLKJvl5pz8wIHzlVf29YIOEpNYANPi1PvAafzwfcPdICBJhbiTa/jR18KlSeoupng enq+vPsqdy+PvQOclhRhYXqu0a8a0BP4/RKukwCQrX7p/jLv6Dra4O/m8Q7lZSriwpPG 06C90U0UGqQ9VAQbP7jbK58xQZBkkMjb4GJxrbUG4+78IAjZ4ZDsYR+aF4bxZbrkJz9E CQrQ== X-Gm-Message-State: AOJu0YyFY+uccSsHRSJNuqwROKtm1FyTVY7GUxw4pK8USr8YFyeB+DYr SgnQqFs/ikPqex64sjSdUHfbUG6JqpLau4I8dbZz1TKKKqKpliBYJ1bsCrQQO1+gmnhn6XXQGkQ V X-Received: by 2002:adf:fdc7:0:b0:360:81f8:698 with SMTP id ffacd0b85a97d-366e96be4dcmr4311067f8f.58.1719300906944; Tue, 25 Jun 2024 00:35:06 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36647e7eb4fsm12112264f8f.18.2024.06.25.00.35.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 4/7] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26) Date: Tue, 25 Jun 2024 09:34:38 +0200 Message-ID: <20240625073441.34203-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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=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 | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fff4be3ae2..9db3b32b0b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1491,17 +1491,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 26: /* CMD26: PROGRAM_CID */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); case 27: /* CMD27: PROGRAM_CSD */ switch (sd->state) { @@ -2064,8 +2054,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 26: /* CMD26: PROGRAM_CID */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->cid)) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; for (i = 0; i < sizeof(sd->cid); i ++) From patchwork Tue Jun 25 07:34:39 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: 807262 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222556wrt; Tue, 25 Jun 2024 00:35:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW6BMfEwPdm2nnaebJKZZyOUAD5GBejeGwlxR9QHiHGq6WwRXg0XROGGuxYqOXXBzzYf2Nf43URfQ14BgYs/Fc6 X-Google-Smtp-Source: AGHT+IHzeIBfET8jJsVBQvdlXbiptbNMWScMlHHKhsfqF1YZilffnVXV7GDPQQKIY/v8LNgor4sw X-Received: by 2002:a05:620a:199a:b0:795:5e01:74f2 with SMTP id af79cd13be357-79be46b75f7mr949386885a.21.1719300937624; Tue, 25 Jun 2024 00:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300937; cv=none; d=google.com; s=arc-20160816; b=whvyjn9zTpKsQb7/aGvBkKL28ArOYIsQT8Vv69qQB+iySs/hvxIzXZ3NPUtIgQMx5R b+k6Acj4MnPOWdW+qK70/nfmEq6V4UzOZtrWf4WD2DsrVmPH1CU8E8SHZ7wT/pCT7djW ilD+WivTzNmQiInZvzHhxH+Xzhuvu92qF0+Ly8cj+lQLjOIyssLn1ERIaINqkjH/lHzp xhiliSgqYEHx5eg+6iq6F25G0+itX8sup2+KFk6sCCif2QzEedG6qmGssfOPncH/Fl8x 4O2DErJXEV+psFMEu/jF/TLzcyLakLmXO1FQabMfQoNW5mhXXYgt/YdnJgxxi3+nKDB3 YX1Q== 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=qb2qfxjBpxYILlILF5IkDh+mD4sc48rfhXmjHKKwuZ4=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=vpIE8nH2t6vBoV/Dy/VkmKPNQm8sGIiduyxAk13TzEFMUATw0wjHIpO/wiw6BdnXvP m3ByyVHUgege4hAb3/lMR/2jWQJsSJmtj7XYKhr+MSmMfJxkzWeMI3DhIf/E90EJPxM/ jxcWgIwDpnkBrsQBYL6MvK77CETzm1jSPGfV8zsRmpbr8/sQ1DbJMUETXTk4ms30gMDt WvtHOXMfayzGVkoIhV78RjDc4oMWhvC2R9+xyHuQCoXBBadrp/ALHPhH9buiTTanDWJx Xv00y70FD5N7uCkyZS7e5U7vbz1Rt229qSPh+JbDeahFdbRkYntNr9y1mw/8D0BVNJya QSlw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a7VOfH2E; 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-79bce942d68si965783085a.644.2024.06.25.00.35.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:35:37 -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=a7VOfH2E; 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 1sM0hx-0004er-Kv; Tue, 25 Jun 2024 03:35: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 1sM0hw-0004eU-62 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:16 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hu-0003yS-Do for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:15 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-421eab59723so39061615e9.3 for ; Tue, 25 Jun 2024 00:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300912; x=1719905712; 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=qb2qfxjBpxYILlILF5IkDh+mD4sc48rfhXmjHKKwuZ4=; b=a7VOfH2EFYw45itsza6Ow8skCBh7gBVitnTzDtjQsS3vddTLfgfvPeWr4LpnMam7rT SagxSnFUxTgSo9+ZvRSL3sSPKO8kSGxOP3mV12JNgVSxpm1le6dFb0YFB07lYrqaExUx ojA3SHJYHLF6jVXBjwV+giS2n7gz1TI0WNaxNQUm1WWZt3nN57H+d7m4uUK3FVsco7lH EuQ9jEO/7WgqJV04UuQGNXnFosiaAkJyQJ0wGHz4nlvwIcrD4Bs4+hGub5ue/2h+K4PV 4GXc8Q3Ckl0Th6jnSsdiwQrW2lZ68BFf9DO+JtisZyn1NidTCf4r1Y9OprMvJ0LSo/m8 eZbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300912; x=1719905712; 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=qb2qfxjBpxYILlILF5IkDh+mD4sc48rfhXmjHKKwuZ4=; b=p+ke/026zrzAlMYVxY7hCMFbSnKfsmpcf6lho76U3OjkvyDfX+n6nP7FAaNK9U4wkA Ksp+rBxPXwFUgvqwHc3P98ZdCRKFqY1wPywsdhspupftTbhRbn4bzsBrNC5yEuQcFD+U Q0TtNVFczGMG9acu1SBUV8aFeynlsBn1ZYiAHYUgzFbJH/+UoF7j9WmKra8UtOsr4oNL PlUbt3aBhPViiY07N+HnejpTIgA3fXnFIBsaG96OMxTxnM1pF/JDT9A9mjgLK02f19rR m2rf7/MZnh/0kPWDfc40nzfjqxaiFqtLFsXoX8jTar5NIdRt1zV4uG0Vg/2EpX88uESI nqdA== X-Gm-Message-State: AOJu0Yzl9Pcizn2btwApiVfOnEhkzEWPiX7qMnxjafeK3c2Xff/CR5t5 5Lxejyb2gvKM6YjOekvnDgmznxZR7rezyydh6Sjox+0BufBT8xTshDPpMrvgWIkd7q8mNB3eJAE g X-Received: by 2002:adf:e6c6:0:b0:35f:2725:f6cd with SMTP id ffacd0b85a97d-366e4f0bf67mr4989189f8f.59.1719300912648; Tue, 25 Jun 2024 00:35:12 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36638e911b8sm11991956f8f.62.2024.06.25.00.35.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 5/7] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27) Date: Tue, 25 Jun 2024 09:34:39 +0200 Message-ID: <20240625073441.34203-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 9db3b32b0b..b0f29034c0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1494,17 +1494,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); case 27: /* CMD27: PROGRAM_CSD */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->csd)); /* Write protection (Class 6) */ case 28: /* CMD28: SET_WRITE_PROT */ @@ -2072,8 +2062,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 27: /* CMD27: PROGRAM_CSD */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->csd)) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; for (i = 0; i < sizeof(sd->csd); i ++) From patchwork Tue Jun 25 07:34:40 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: 807267 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222769wrt; Tue, 25 Jun 2024 00:36:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWF2C/y0sY2pEoFcwBu5E4NA2FA2XSwKKZqoSKIUlfDpfcIFCMVBFt9/vP2SeALU+bw6X6bLtB2oTPf5Sgppgv/ X-Google-Smtp-Source: AGHT+IFrldWZHFeG1msuYc5IfNwlFHtEKfZbNBb+LYHi/GcToIYQ2J5ezJkaV/z3JNhqKiiTd9Jg X-Received: by 2002:a0c:db08:0:b0:6b2:b2a3:67ce with SMTP id 6a1803df08f44-6b5364f73bamr71229166d6.51.1719300984801; Tue, 25 Jun 2024 00:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300984; cv=none; d=google.com; s=arc-20160816; b=JoX0nmBHj+vEOo0lDP1RdDCuNWNiKxYTSUBDsXUp27kd6esawL/+KfSW4ta6OnOsJ0 2nyGnTJ7B+1b8TpBiJEYu56zxDr2605gaesNDNKZLde84XmQRP2Qj9NT0Oxg5hP6KrJ/ VuOcZ6OpfKN+rnTuLZMKBcPmJOj6ICa/anlFcgUdGAAnpgdOUSelrzwhp3vcIG/0/mZU 3qomdIhvri0aiMhymyUyXWYnWQsSlLQPAC1+fn2iFE7qxeZNeF1y8w+tc4XC+lcthsGD TQSwFiG42pjbm/pNJdFwj2g2DU0LJv//cmZzg0pcGgx4nGKDwrZyn83yqJSevDZWhQvo AKcg== 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=pU2MPUHXpvnSU498pOire3lRQStnRBiAG9dQFz8I0B4=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=qpDG0paIHzQgujZGcTqw7CtaWvk8NPXram5qMl/iNZ33+Nt7k1Vi43Slg9Zp6R/Vv1 bFYAj5WAmtn8lZAT5rmay12QSHj/9pWpG0JpKzoC5Vs/Jt8Dkrx/7IjGhEPJ0x+qxgl1 iC93SdnaPnEcKABWKo1zYu+W1PHufeDsfK1pne1cEtwd0qY4GBq9USJOLG2KXCqVJRCx satZqPIkPwrQp/uRLqfz6Kt9l7cJrd6TGgFpOphRs9uU8GczNi36wQBpEjushI01wBA8 b7CpgT+m+aMSB9OiO6nDPKGtv0lWkjJqcfQiVi3Ofj+mR0Lr6HUvvQJwTgzF0cY068vj ZYKg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=azfw5Ums; 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 6a1803df08f44-6b51edbdc5dsi96312746d6.263.2024.06.25.00.36.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:36:24 -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=azfw5Ums; 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 1sM0i3-0004pC-MQ; Tue, 25 Jun 2024 03:35:23 -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 1sM0i2-0004oi-5h for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:22 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0i0-0003zQ-Ad for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:21 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4218180a122so39272015e9.1 for ; Tue, 25 Jun 2024 00:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300918; x=1719905718; 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=pU2MPUHXpvnSU498pOire3lRQStnRBiAG9dQFz8I0B4=; b=azfw5UmsPcTm5jDYxm4cB5pZsdyyIz0YaRLI9eAUrOkLyijjFJG7fYnhJFOhG9gAWu VlbMKTyUjXXtWLYeGFyDm6O0CuUuECt6BzQJ0bFKhErq8mCBk5YTvd/bmZJDnWdCWrk5 j1j/A/wMHusYTGRPZlepDTUpQqSUOgBMSFBNXbfjsEzrOcRJZkg9e5OtqhPM5Rui8urh 8qE9NZDrloMCW3GnjrCA8aoYTuUJFbf+PmbwwcupElAcHggDUwR8xAXWb1nl2KgT/Mxp lBZ53dvHSW5zVNUmsaO8rl4Arxs9CCpWdKYnlHrcgewf5AnxZLtFSjv6yEDMsHMTXYBG +IZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300918; x=1719905718; 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=pU2MPUHXpvnSU498pOire3lRQStnRBiAG9dQFz8I0B4=; b=d/ApCp6LQwuxHkdnC3DFNSdYU4vnuRTOZSl3Rm0fpj+gvUw7E/LRhBWnM3UPrK+P4q LjjWhhgI9HrySFuXC2hHVGpxLo3wd52YlJLZmd5sBUvwPnOOaQ9Sg+CWI/dXgQI74v2E yOn8E26J50D7PeL6iSw4amkbPUw6U5hQh2JexasGEPAt256EQyyI133Q9m7GkQxCe5bd LnsB+PDaf9RhgY650ior02dkiWw/BuqwHTsQCqwP4Tf8xkacoXQ9ITUD4IJVZqSgmAbL tRo8hnfDlHH55HD8UFoMWmxHjuVowQZRSBhcJL64+fR/n8TPayERDpDkoQQUIf6lP3Ye P9sg== X-Gm-Message-State: AOJu0YxLYYGs09sClvRfDBJC8bNAN0kQk0u+ZOdnZepRoVKBSoNh0tHX Q29W8FgkJ2ytOjeJR95YVkL60AIMYv92QDTxO+9j/6tYQu3DkU3YPcUQCSL9IsKKUDASMuPPhbT 0 X-Received: by 2002:a05:600c:4fd0:b0:424:74ed:dbfc with SMTP id 5b1f17b1804b1-4248cc66abbmr49931405e9.35.1719300918307; Tue, 25 Jun 2024 00:35:18 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208b4asm199313845e9.29.2024.06.25.00.35.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 6/7] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42) Date: Tue, 25 Jun 2024 09:34:40 +0200 Message-ID: <20240625073441.34203-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.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=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 | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b0f29034c0..82b44b65e0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1604,17 +1604,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Lock card commands (Class 7) */ case 42: /* CMD42: LOCK_UNLOCK */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, 0); /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ @@ -2085,8 +2075,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 42: /* CMD42: LOCK_UNLOCK */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; sd_lock_command(sd); From patchwork Tue Jun 25 07:34:41 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: 807264 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2222566wrt; Tue, 25 Jun 2024 00:35:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXQdJC0pkfT/05NQlCaIoGeQ1IFRvLF2OwpUfxSzYwsOLRzCcwGM1hAsqZImRsnrVglD2sYw5zXOXXqizstLweD X-Google-Smtp-Source: AGHT+IEYAmsjz4ah12+UQ65IyXj/n/g8i2VW1G9h/ibaBQnAonFiX+bXr96sYxrsmdiniRg/6fEw X-Received: by 2002:a0c:f349:0:b0:6b2:a5ee:4911 with SMTP id 6a1803df08f44-6b53bccbd0cmr81156566d6.20.1719300938865; Tue, 25 Jun 2024 00:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719300938; cv=none; d=google.com; s=arc-20160816; b=PeVgR+VHyy41wqfTdo0HetSTA+bgem/vZyRn4d1DsD9wDFQ/BWZYBYox3p7+eGo6FP KptK7OwKj9Da/ZeZh/1HhBTE1tz/1GIFDoyF8BPtiRgZRrxqiqiR1KmB5WoxL6OaPCqs jH+rER23Zz7H390hWQffaWXBu7C42qaGNk5cWnDp/vrD9GVcQ1MXeCpOnBiWs3CmkSQm xi3ZPaTccE52vpHHkITIhmRpz5ulS5c6UD1/WPKH6xzFqKCRYW+m0fx6TsB0zbFVgdD9 yDuxcBWL0j+oN3DjqVkMDc+rH4IjQDdXuyfqje2+Q4/jaBa4rAn9ixUb6bHl54o3xZos iTpQ== 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=dkL+F609blkCP7YhkbDtjFQ52Ff3yQ68oguPONbJIG8=; fh=RCxNUJwt/amfcWvs/lXDf/JmxshGBXr892O+ARTFYyU=; b=t1avHIuu2NGNZ5QNBPtjgHjbeKDZz0yytwfJKhj1eD1yE/OG3AjsHC7Qk7J/HPDb4q f2QO7amQ4Wsvj3Idw+vhsKot8PRQc1pyFmIzzCvxrTm8nbtA+XNR1TDX1strOfBxtTz5 po2sdxtj6gi4ukaKfHu1k1Jyo3lMJap6WEW2c0o/G9TWeF+f0H4NweJm/Ezju2f8Sxgi LnK2ELpPEHSxoVHS8ZqdPKqLFbjbyPV61vLiUxUfN/70CjqEV7ID/Xpp7fHZy/eYM+o/ VeL01EH0AfYYWn8yXbhQ05DMqVGRpmCRdJxoss9cqoRPQnF5U7fjRhYQjcCh8zDOJuIX 7h0A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XhjLj5bR; 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 6a1803df08f44-6b51eedcfc9si98248896d6.396.2024.06.25.00.35.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jun 2024 00:35: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; dkim=pass header.i=@linaro.org header.s=google header.b=XhjLj5bR; 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 1sM0i8-0004sT-OM; Tue, 25 Jun 2024 03:35:28 -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 1sM0i7-0004r7-7i for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:27 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0i5-00042o-M9 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:26 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-424798859dfso43620855e9.0 for ; Tue, 25 Jun 2024 00:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300924; x=1719905724; 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=dkL+F609blkCP7YhkbDtjFQ52Ff3yQ68oguPONbJIG8=; b=XhjLj5bRAIS9pow3Ewos9Vqixrh/KdJ3/zW010ce7gV05yssSWIg15Wow+eYIQj73R soQKvnhLNK9Me9MawxbuHlVfxvDbdo8Is9RzbtXEZHvdE1Wvn7ej7c8KUHVgBAksIH5L MvfrrUszAAnAf/yrS/YWKyDUNcxD9KNugFT1z6ds1aEf/yzTS94etiLaLOxkqlm9T4qg ftGD7yYzurTfQvcqGcwCRLxeERngqQqSFdMcKAtp7zpmxHh0TO8T8XTtIF4aM8iEOXj9 ATwxKmRuUUsDo9P34S5ulQHXwGMPBdSB9EjMyCBz2X4EbW8vsGHFiXBObgJs+8tG07Zz Aygg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300924; x=1719905724; 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=dkL+F609blkCP7YhkbDtjFQ52Ff3yQ68oguPONbJIG8=; b=RWDB/HbLe+odQMZiGMWDK6w73Llr3/mYEyq+/lQKXv+gjLN0LfCeeirdtJiBIUOkE/ Ezl5cBNNG8VIHUyxINyn7bCIsDiqf5/J+6GAJlTRh/MgPcCsdgMymUBCyW2slWoQKc49 aSavk4kVkNez4okKyHH1yOtqH03oiVGSo3HCg7XjuIyPwc5Ytn1Pqo7nCLFEpP4u6eSz oiv0GiqY2LVzdppXCpcgoNVLcelRLq4Hdz67HrhGb3TRrI+AGHm0Z7dae7bJXPVSknDi zctcBRrWQSJ5fH+r2omILOk5f9Im428Wo0y7NSbZQqyXqhBpe0BNBDxTfwERuSau/fBN 1WUA== X-Gm-Message-State: AOJu0YwgpPzl/e2vtAHGUQdX6kS6I5hSCiOm4TkgQ2cj/aTjbPT5MSbv f0RPjGkn8KbHiN6+2pI4qOF0Y0ViOGjoLDO73uCt1Kg1GMx1DHra7MSxiLr/gnU4X3i/1OcpVB5 t X-Received: by 2002:a05:600c:470a:b0:421:7fb6:511e with SMTP id 5b1f17b1804b1-4248cc5931bmr43876865e9.30.1719300923941; Tue, 25 Jun 2024 00:35:23 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208e13sm198393945e9.36.2024.06.25.00.35.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 7/7] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56) Date: Tue, 25 Jun 2024 09:34:41 +0200 Message-ID: <20240625073441.34203-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.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=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 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 82b44b65e0..fe2210d65a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1633,14 +1633,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 56: /* CMD56: GEN_CMD */ switch (sd->state) { case sd_transfer_state: - sd->data_offset = 0; if (req.arg & 1) { return sd_cmd_to_sendingdata(sd, req, 0, sd->vendor_data, sizeof(sd->vendor_data)); } - sd->state = sd_receivingdata_state; - return sd_r1; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->vendor_data)); default: break; @@ -2085,9 +2083,8 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 56: /* CMD56: GEN_CMD */ - sd->vendor_data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->vendor_data)) { - sd->state = sd_transfer_state; + if (sd_generic_write_byte(sd, value)) { + memcpy(sd->vendor_data, sd->data, sizeof(sd->vendor_data)); } break;