From patchwork Thu Jun 27 16:33:57 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: 807837 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894354wrn; Thu, 27 Jun 2024 09:34:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUXbUi6yh5/TJman//boDVpteccgmzzAsU4A169CXB3rKKltpBiw4C0t9c945E1XEJ/io2xLK5Qnbmgr3pQSQRt X-Google-Smtp-Source: AGHT+IG3wLA9iCNGjj82vr3OOb3FskMl5fUREQY4hNQMYLttrk0p/ZGoj0ziCtRteSfT4rfN+ntV X-Received: by 2002:a05:6122:2524:b0:4ef:4fc8:ab6d with SMTP id 71dfb90a1353d-4ef6d80a590mr13331076e0c.6.1719506094478; Thu, 27 Jun 2024 09:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506094; cv=none; d=google.com; s=arc-20160816; b=cl0hUOV9BVqakDgT/tYM2F23NYytELbukJkAJnzB2JbI//O2uEw3iIhBVtgF+2TCp0 6kFNr1aFRIFA3wBDTN63MggRo9JREDQC2Y4OpZc+AhILnTe1g6SNAmdxtHnDCA/dvPbH MhYaC+jcPlPh+ggwOQ/VuhgBEiL7ecFjcsbgokM6DONsI8MhDv42EUOvdoCszb6FAn+i JdM7c7/yRSnTOE+tA371shiBh0EgtJB9yaNHV1PJyon3jd9dtKRjlNNJQ0e6phXr3Pxi L80C90h7fMtEqthDfgH5IvxDSWzzdZdGqMSKVuiJl6KDF/5ot41mK2MohBd8KJm6e1RW udXQ== 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=dnn8g/1r/IDbgXO0nM+fG6kuhQufIGWzDGBB4WRk/v4=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=eoj+5ukZZlFds0i9bOfOFUc+YPngGnUGB0kKNkMWYnGdOphx2W50A3z4SYXgMI9SOZ IzsUukuh9nvnYjWNybZaOwvhUC+mtcaKdWAoc68xDFRBRLaXw+nX4lzQm4kgQJBEyHH0 Wvyyp/DjRHah623zvrxu6Upws9rrrKdebh0wqSQdZqXN6aEsDo/HJbdTnCKEzI/048V2 cV/kobrNDahBQJl9aWB9tn/1pyPr7iyf4QSxhDdGcOClhERHm6CUIXOz2biDR1B4aGF1 wzNEamuGcr5j6iBHPhtxV359y+j+v6durm+VEaUbNqnYf+brBhC2K+0DD2tqb/z+3frT EtqQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DP65HpRM; 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 71dfb90a1353d-4f29224e5cbsi4558e0c.157.2024.06.27.09.34.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:34:54 -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=DP65HpRM; 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 1sMs4o-0001UR-7Y; Thu, 27 Jun 2024 12:34:26 -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 1sMs4m-0001Tb-Af for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:24 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMs4k-0004Uz-KV for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:24 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3672aec418cso1316020f8f.0 for ; Thu, 27 Jun 2024 09:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506061; x=1720110861; 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=dnn8g/1r/IDbgXO0nM+fG6kuhQufIGWzDGBB4WRk/v4=; b=DP65HpRMXK9/XazTsYgxsxuuenuEcuZ3a9rYP03uVLZeH8DYhRT0mdHKMOCVOe7Cq5 t5r7H5RCiMlMXRjLsoXiDx7bmdGkBwQFN/nKwU/a8Jr6hDippZpDejunb3B952Asytl4 AbLJxgcm4sUdGUG8NWNvv1rGb5IqG7pxmxZ2gHvtekyXrYPiZgom1McWNRszU9heOrTO lQegG4fVAbvWd4/NyZJ2KpzCPk0IDbuFHk0jMO2jtzgfapC02Ir1NOtkdWuc8Bnt0iZQ k7NV2elyfX1ZCcpArh8jXVYtZuqIV8VQLMmMQKIuBABj2SkAqGi0dnO18s7lExNmHNvf TtEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506061; x=1720110861; 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=dnn8g/1r/IDbgXO0nM+fG6kuhQufIGWzDGBB4WRk/v4=; b=YCmkGEF+h+8jFoVF/gkV+69sGJewBrGe+07DAT9zHAg5xO9w9u0V/i6RmJG4+gs/9I 2hxhHlyFAzg2NnqHplM848DRfNOahgozATyfKutZoZXvDrqUek4HYMlUero0B9WebCFV 3dwh5unKwJgUoPE7hOBJFzpocG+w6JCcxpigmz0ir2ZvK1xSptxbsmdBKt/LheH2XP+v R0lNVCOID7VCQJ7YuEvHY+NyUaWraVcGbcgNsgUoXQSCwNIzaBYIQ8xejNF5g2bcArYQ wsV2VMsM9zieC84f5+esPg28/kWzcI5QZg4psZTpjl7IzgxJLx4ImMyVeD6sfP3uUgyr NtGQ== X-Gm-Message-State: AOJu0YxsO+1EOeeD2GD+hizZ3y3cjkZGkHZabX0tWs0dLNYEo70Mz7iL ugJ9AeJdiGHktLNaJTky3MEDXZW/Ieu2O+ngWryTwPJda1taHtYQLZT3hdQdRzQ0r+P2fFsgWQp BxdU= X-Received: by 2002:adf:e390:0:b0:367:33b1:e82b with SMTP id ffacd0b85a97d-36733b1e8b7mr2566041f8f.68.1719506060714; Thu, 27 Jun 2024 09:34:20 -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 ffacd0b85a97d-367435852fesm2368830f8f.56.2024.06.27.09.34.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:34:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 1/7] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte Date: Thu, 27 Jun 2024 18:33:57 +0200 Message-ID: <20240627163403.81220-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cd308e9a89..690a3f275e 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1100,6 +1100,22 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_write_byte() calls */ +__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; +} + /* Configure fields for following sd_generic_read_byte() calls */ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start, @@ -1953,6 +1969,19 @@ send_response: return rsplen; } +/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ +__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 is consumed. Configured by sd_cmd_to_sendingdata() */ static bool sd_generic_read_byte(SDState *sd, uint8_t *value) { From patchwork Thu Jun 27 16:33:58 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: 807838 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894397wrn; Thu, 27 Jun 2024 09:35:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWKa/n+wm9lJx5qkRrBnG7sbeQrjsiMOJTYJWb/v+Ek/2d0GO84KHO9DIIQQke50Ow4adeffmd00XKyOshO4Kl7 X-Google-Smtp-Source: AGHT+IFzYNZX+P182ELJwfmYTmIK76msJ++s5ZbgMCIp6P5J6AHf763E1dxrSfoq9HGpfoC3tfwH X-Received: by 2002:a05:620a:290b:b0:79b:b571:4c1d with SMTP id af79cd13be357-79be0c36f4amr1772614885a.22.1719506100659; Thu, 27 Jun 2024 09:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506100; cv=none; d=google.com; s=arc-20160816; b=wKiuB37d01m8AWXf9flltsjbYXqQcZNJsSQrDL2JTVgwlgxmMxSCELPOmcDlCPJ6do rWQD8/cfDIOU50a5Xlm2OVnUiqFqVb2cg81Q0506FHx95kCdPdTWr5nzq9fbDOQk1qKJ OmnhbqL5cqp4QlOkVwGcv2940SE2gc5KiaC5Gy72aHOgfD2K6JVtJDQtrRtTDXsGyLOd HxykSR5CnQiERyFpPSYdowbHXQCC8YE+/d3BLsuzNT+jQGZUUEQVEy2wijx1z/rcgWuT gAO7G9xf/OOcOJb04IVunMdbDJRVIMyRW6ihwyNW6Q/Hb8EJjvwFP54BDWxnKFrHYtuD IiPA== 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=3vBMoM//nVZe9CjYveKRdhPX/dFzNyrTxzPZ8neKDDk=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=stRFrzJbSSKbK9t96Z0Kb+W3Y65vgdwOe+d+crBqmF8cM+yUebNtUDED79Q4GvuUYa ujbXHD1v9TwlJuyN4kafZHFMd5oxbo1pgEUusuC/2lf4gi7jAjI2UheaxZOgKlaa+C16 i87bEJIU6NXlewdzJY35ozZgPjLgkhD9zIB6NL3zs23byQocUz8RcYQcoPhsd1DMxuc4 Wq+POop+fhfpaFgm1J9rtffVK57GR3pIw0MjApfzDqX3fkl+DB070nTTpXDgxVlsMEdK HJrX+RL22fFhoTZ0vQCSmQ97kU0WIO1AYQn07Sy4Vj/4fm57tIx3W5FEedWz3z/JMTw1 0rfA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JiCddBWr; 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-79d5f6d3305si137875185a.743.2024.06.27.09.35.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35:00 -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=JiCddBWr; 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 1sMs4w-0001Y2-DM; Thu, 27 Jun 2024 12:34:34 -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 1sMs4u-0001Xd-U2 for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:32 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMs4t-0004Wn-CA for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:32 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-421f4d1c057so63812855e9.3 for ; Thu, 27 Jun 2024 09:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506069; x=1720110869; 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=3vBMoM//nVZe9CjYveKRdhPX/dFzNyrTxzPZ8neKDDk=; b=JiCddBWrglWdXlEz/eMnm2CAMaEA1zViytrpsENmb+qahURIp8UY0JJv4UUTwSZsrU uHhRntqiSAonTAU9wTFgY3WS9TXAfPF47RfKehgGkkwUurbbYO5P4W9y/N8mDDXd5I2X y7JYu1Fn6TC7pQ7F7UkDLLwkwlRA/p7JWH1RGQYQbbzmOr2A1OemRJs/dvnQC2WaVmIC mcRuwVUUYsEjaZCE/JCIVyYgqF8Cc62Y1H/ryVm8fTGQUPDmj8Mr5GFbFskXU2cirOXo nssCZc2OhFxrVF7ckSqTa1FCkPf8O9KPH5wZiltJEEopHIHn6wmp8xKrQE2eoNKTWzlj dmyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506069; x=1720110869; 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=3vBMoM//nVZe9CjYveKRdhPX/dFzNyrTxzPZ8neKDDk=; b=FbZSTMTSWpIPkKt7cqyhxcN1vog+UksAQf9xAIfUy4qBN7QnGIaJAX6Zam9xw5K151 NIxSvFbDP/tB3fYFl1w/Ey7+NJmxWG7NYvmdJLXmVzZeLvIfKs2oNroU9ppVIJNs8YNu gMYMh/MWOFFgIbpI/JHqQyFhodFiD8yDg5l6h3N0XPXJke435+2eOSEDhov/+zgM8sR/ YMvQdjpSa/LmoBa4ZuSMoHrJTpozEUsaBUOON80n5uvY6h5aa22b1PdbTG8Pu3dIcjpN MJlNARjPSoUDozNK0+Moi90kpq+VNNXEJiaqylxtvHiBc8kfDVYz1sNyw7j5uhd7tfkP 9/Tg== X-Gm-Message-State: AOJu0YyZ+mehjLeAQw0CBxru2w/Ixw5Yl2owL9Fnl3sz88YI9XQnmyVX sM2AkUxM4AVbarcGXVOdYs//Qb+VcsA7UTTz7thezLPJJjgi9a0HMiTh7YFFkM+BbUFFRLaAMK2 3DT0= X-Received: by 2002:a05:600c:4851:b0:424:abdb:9c67 with SMTP id 5b1f17b1804b1-424abdb9c84mr40851815e9.40.1719506069544; Thu, 27 Jun 2024 09:34:29 -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-424c837a958sm71106395e9.27.2024.06.27.09.34.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:34:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 2/7] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases Date: Thu, 27 Jun 2024 18:33:58 +0200 Message-ID: <20240627163403.81220-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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 690a3f275e..5dbfc8000b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1461,6 +1461,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 Thu Jun 27 16:33:59 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: 807843 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894728wrn; Thu, 27 Jun 2024 09:35:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVlkvdI+lZbmQCp29/L6Dly3WuBNa2TrbQ0RlWy64I5B0VC55w/gUTKKI8r73dmxtdHixLqFGGmEl51u0zIyl8o X-Google-Smtp-Source: AGHT+IFgXnmDatdYMQZP8yWZwlfC/D05wF1pJXE9LtpuI6KbxDb5NPzrMxvt3ujmeB8KAx3/p1Qf X-Received: by 2002:a05:620a:44c4:b0:79c:fd8:edb9 with SMTP id af79cd13be357-79c0fd8f5famr836420585a.28.1719506145782; Thu, 27 Jun 2024 09:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506145; cv=none; d=google.com; s=arc-20160816; b=sh5IlhS1iymFrV/Y2b6UZysge8j6nCip7m+qe9movgTGTgGk6cKSCKeWKzES1U1GKy D0EVSHRf82SSjulqYD+x3hWhfmp5JluD/zZQxtJCby6/49E7Wiucf7xn28x2E7dRtwa4 8chvbQX+UM4pcWpgqheF0J8wsocxQlAe0ZMfcbQzi9V7qvSBzTxsnDMgwTMyv9XHbMJa tTAquG0h4beHGiAwWsSAlqTuJ7Fpme2dqppvtmnELAn/QVZL0IFZn8iyK4/BgXek7NuJ 27UX8mUNO1819ScRgZ3FoMQfO+V0ub7zk/e+RM0X0ih/GACUNwDs71Nz3swelwgIbP9i b8iA== 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=6OC5ZZTN2g0zXo+PgkNXxQ15/x/Un0F32fTNODaUpCo=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=ad2LXijUX6yerPxGReJ4bMhA7PlQxcSe7rTa9gJ+dvp6muw42TeLx1iw2eaGHwMYrb TjUNwXbIPYDb1EBnaEKuczsdyRk7W+ZYZr1yRzRbRADTf0IaK4LZJOYYNEYJXYHbXNag D7Ppkf53WGVeFMCbITxnMSZ68b3Yio3qS9YPWQRD/xfWdRHwAoLGxqwaImS2OYUlmlDH HPup9iDCmeyvPhq4VznolOvJOi+8w29kIxbV/E9pLnuv9NFF1/7Ke0Lg7H6++oqAbnyJ ur0nnHeesR5G4bOhplnxyDqZay3GBEkRvmpssuUvhkal2cIXZDl9bngZ10cU4EB1IgwI PtLw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rcf8ox58; 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-79d5c8b5dd2si162443285a.399.2024.06.27.09.35.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35:45 -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=rcf8ox58; 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 1sMs57-0001cV-4x; Thu, 27 Jun 2024 12:34:45 -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 1sMs55-0001bX-HB for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:43 -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 1sMs53-0004Xp-TF for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:43 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4256788e13bso4476365e9.2 for ; Thu, 27 Jun 2024 09:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506080; x=1720110880; 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=6OC5ZZTN2g0zXo+PgkNXxQ15/x/Un0F32fTNODaUpCo=; b=rcf8ox58YZWChJUnHR7hZr1l7eWrvp2bxXw+qa2eBeZGkfQOGudn3z6+fv53un/lER o+gxM4IXreEbzLuFLMQlc+SM7fTPObaPgXAlEnJoc0wQ7zAd80+HVTMl64/+crlae/t/ ID+uZi+dbxnn0BQ8y3oqOek6310yMZyiEz6lEUaVS4N+g3UeEhwyFlizPVjgujbG/KYs vEQKzrnlOijrixlsCdO1EOnjZDbwlukWbsU3OHW9MxfcMFxsMvZjwnDa44G8nau++y/B MZZONam8Z+QOln9UJL+5KpdrP5gx4Xf6JvcHdscCpzfPhYJ88bSLd+Xw2U0iFbsdqLay 5p5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506080; x=1720110880; 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=6OC5ZZTN2g0zXo+PgkNXxQ15/x/Un0F32fTNODaUpCo=; b=lt/L5QcZ2xYXcyRTL7PM1ItPQytaUbVQExrf5z/QGkOOW2XTSo+r/EeAW04mjGPIgr yEFlhhgl2BnRkGd2dH+0fPHeZFDL63VSpVk3aWtbWd5HE7dOhY3xmLhn0EMblLyKosUy VeRbZ4GEAFgKqT/hl/w/zTT7flnNXkwSxbz5OK39Y1JxYUmP5osephX/ZnKci8KQFyHH 5ijSCiCMjwQfl6z078nIpwqmKtdn/NBdHMtxOzK0/eyyRozLkCgDah2HJy4rnWD2b3oL HZe/ZmRfaKWe3BY8tFJ9w/rNd1SFMBHoUpPGROmO1G95EAz0OCmJ6VJ3XYGMFA/vzFHc TVFA== X-Gm-Message-State: AOJu0YzrYXXtVWFWR3sAMkfXB8ZftOzbaWNwlKroejo5Z1oASP2zpFF9 6Z+lNP627Rz5eU42b4VXv5iiMh9UX4ToGiComRkrropcBP1osXbkZlfi/bU2WRIgt9M6HC1g2cC 9phA= X-Received: by 2002:a05:600c:6b16:b0:424:a3d7:2a89 with SMTP id 5b1f17b1804b1-424a3d72b27mr54802075e9.4.1719506080055; Thu, 27 Jun 2024 09:34:40 -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-42564bb6cccsm34736665e9.35.2024.06.27.09.34.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:34:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 3/7] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24) Date: Thu, 27 Jun 2024 18:33:59 +0200 Message-ID: <20240627163403.81220-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-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, 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 | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5dbfc8000b..4a03f41086 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1101,7 +1101,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) } /* Configure fields for following sd_generic_write_byte() calls */ -__attribute__((unused)) static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, uint64_t start, size_t size) { @@ -1470,10 +1469,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; @@ -1483,7 +1478,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; @@ -1999,7 +1994,6 @@ send_response: } /* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ -__attribute__((unused)) static bool sd_generic_write_byte(SDState *sd, uint8_t value) { sd->data[sd->data_offset] = value; @@ -2045,8 +2039,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 Thu Jun 27 16:34:00 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: 807841 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894644wrn; Thu, 27 Jun 2024 09:35:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnxpaFAzZhiIsYyRqRl2Z1U4PhfZn3CXK5js79Vm6S98VONd18uDwIP2eYmEzpdcmaTLpci19lPAs6WhAvaBwX X-Google-Smtp-Source: AGHT+IEBjpaZL6GfndwDsbyykzBig7EVrvuPUz28JM2R+IJvwiH64/eE3ZjTTwO2ApfiySSLQXxc X-Received: by 2002:a05:6102:366:b0:48f:8f72:ecf8 with SMTP id ada2fe7eead31-48f8f72ee22mr2113626137.8.1719506130424; Thu, 27 Jun 2024 09:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506130; cv=none; d=google.com; s=arc-20160816; b=Gp0q00TA8xyqGCgY8r9ZdFlHwV1onpHAWS6mfiUw7R9mygZDLKwU4sPb0Bbr/inMl8 PT7TMSvsNkUWBHrCqhECGx+3uajTYVQV120GRryLwigwU9Xf4PtVYyDFyHgYHfoM5URE U4ISHOKoYFg+QQ801LhIdQ1zj/xeXlzzOw6I46ge5aFKTnsgXxZjbYAQBejWwou/eQrL oBqZu4JmaWWzo1+Vd/nRhEX/Oh8feVsMp2lF2VPv4tizQC98qJIxxwkf6zje/mKSsAHF Zteijx1QCxH8V10prtV1MvevpCwYnoVcGCEGgGq7HQ4Ph6I5mTV5uFAxTepD9Mjfpgr0 +eKA== 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=wBDncTLnw5e5+FewhpyrEtD081BWahb+ptMB4QhJVa0=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=iFCr1GBLB2liGAjs5fCa4eJLj1QfiCDjpdmex7Jf2v/kLhH4uYi6EEn32WUS5siK7f U8d4Rwp2/NpwcTfGF/mgIlWe2RogBZay8Mam6ZSN1vyONHrDJpX43vpWZ6ZoAQHhS9a5 CZmxf0JTkWqOlSngL0uLh2HzeQBiGeqA7lyw6+2mWe4kNDkPdMMLu7yn4P5mU4QX07eI apAHHo76hYnqU40d86Ao2toTrrJ6AbWIGaiFT/YcdN9E5b4SnWZiA6/oCe9lqlHoKx/E bv6hXtOXhRu5q72jvzn5CNiG4SvNSDvIJ3yPQ07BeD7/toHvTBpc2uC3bfPJ1BLZqI4a z/zw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SN24iFVg; 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 a1e0cc1a2514c-80fd1077511si260445241.22.2024.06.27.09.35.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35: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=SN24iFVg; 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 1sMs5G-0001lL-Je; Thu, 27 Jun 2024 12:34:54 -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 1sMs5F-0001iz-NB for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12: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 1sMs5E-0004Yq-7G for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:53 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4256742f67fso5169205e9.3 for ; Thu, 27 Jun 2024 09:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506090; x=1720110890; 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=wBDncTLnw5e5+FewhpyrEtD081BWahb+ptMB4QhJVa0=; b=SN24iFVgfiw6f7qwlWKvnatbwKFQe2pfysgT03Bdn3W/bGZ1LQ5vIlBHqw6YQEJJuc +9y3umArY3lxpVjT+BZJUNmXapQVzh6vMIZXu8VjiuDDf+O3q2i78jQliEkaLA41DPjj EsKt5a8zgVS9U92BS0qLO1VEi4aFrikD65yp6PRKdQiNIrnXH4IjggNFahIoEzWve6UE QhumdqmmBTBQtXe8KgqzoVVzo6Yeqz8r1HyJrDcErhX8iboRKE4yIyysCf8f1Ttjsif3 XmxOxRr4x+6ASjNOB9fCL8gjOTjUDCV9AkRM3GRbbU1ZETp+VlygStDxzUARU480hBTc M7+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506090; x=1720110890; 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=wBDncTLnw5e5+FewhpyrEtD081BWahb+ptMB4QhJVa0=; b=ieMiWCItWAvQFF0n/v/C3ib7Wn9hY9YXzFuWKAFEbS8KhCprwoZLjTzW0lsyodPzU6 c5I2uEIdSbuDzKVWpwzxTJg5tWjvlGCLyd/TA8JPbKzdZmz9OPnQe85sLSNbZMO+Xtqt q7XkH3yClXHS9yghU8ELz7cyb2Znv6N91zTVm12fLk/w+YHifAx1Z0hXpS016s8L9AKq kDPo16OL8KEw51VYMf9awixdvHlNbLhnWClrLH7vxUP7kKEr2mdqBfW/hkh1VRz+4awv Kdfd2JGaxrL41esp1wOPLSOrZLSjlS02t84FtndklIAdND/ZmH6DIL6011h4G9voGCS4 sAuw== X-Gm-Message-State: AOJu0YzsDCJJxU2MLtg/Fi2bzpiMVlFP64thRxHDxJa4r9k2YAVXdFLO x7dviyAphkmYWRCAbX0T5CKnRQ24O3yOrMiSb456skJsv/ap/s4IrMD4mysZwNL4Gt9UoMSMiyY Ytt8= X-Received: by 2002:a05:600c:22c9:b0:425:6275:f7a with SMTP id 5b1f17b1804b1-42562750fbemr28834225e9.15.1719506090468; Thu, 27 Jun 2024 09:34:50 -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-424c8280a87sm75720715e9.24.2024.06.27.09.34.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:34:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 4/7] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26) Date: Thu, 27 Jun 2024 18:34:00 +0200 Message-ID: <20240627163403.81220-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-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 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 4a03f41086..b9c72a0128 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1515,17 +1515,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) { @@ -2088,8 +2078,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 Thu Jun 27 16:34:01 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: 807842 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894643wrn; Thu, 27 Jun 2024 09:35:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXoVOOZ5kEyrORENeFgF+RJ6s1nsVqppUGuY/WQIHaiO19E9DLLbefUNnTYp+mgIQPr5OuVu9OgWMbnHWqjgr/L X-Google-Smtp-Source: AGHT+IFFBuuFxwWBpgipgQtBGkcgUPyjOgIhNgzS+gHxrum98zi4C/EDAGvTCuLV0ozxDkNGIcrd X-Received: by 2002:a05:6214:e4a:b0:6b5:4e24:5b38 with SMTP id 6a1803df08f44-6b54e245c4cmr181868796d6.60.1719506130463; Thu, 27 Jun 2024 09:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506130; cv=none; d=google.com; s=arc-20160816; b=GO8vmlVWklUKwWhpU0ianUYUkjEOv1vMbQoItBXYy0rkTYmp151vwrWiAPp42ajtCz 8WIh/711J+XxOS4bvSgYFdsJvd3CxRQ++iMAUSx+Od0Na8FXIAmT8l1B9HIf/Nmvy5ok yUe5rSvwaAka2WXt5s2vudPBflMPfPJwEHn4/6eLXnyq7twjdzrwCBNPmBuA9gYGPCaH tBlAFjOxQ0ZjYuK+ro5ot/zww1PTdv1XQ0bb/RI8CquNYzBNLogf7a+pxhu2uA+p5kGs UwqhWkeRXRQC453GS3PIuLLUOOEWoizkE2NdGNiRyB2Hzp+sVew9n0vnMMEVq9txUpch ys9A== 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=R6Piulxoj8zPwW1Yv8YFFcFYZqBjXPSZ0pu/dRDGp6Y=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=EUlHTGGLqmlzPcgKnO5fwoTR7kbsZ9HQn1uh1jAeYOAIpsFysQ00q7r6CCOfZsoHOZ TJEoCIy8f3aCBE+y/L59h9ZZn9GM7prGZGsfv3BpG0/EbKTNgJW4NG3nyFKxAe+zYqyS 93cVIF2MHYcwbAAw2U0J530rylo6gACwRRN737sc2Zoo03b5sWqIwgvxN2g5mjOPB6rH yf7rNH3kNCHk6TVxMvkPRObi5/HC8rSk8+gUpjrXBlMO1yoSlqIhGof5hPICSebzyfMU ZUsctUdtjcnBwUDLvQffEvEWl+EywLNtRa7EQL0DXDLCBebmk32lvQnkFvKjfhO2m4p4 GdRg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S3l07bbL; 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-6b59e3631c3si260366d6.107.2024.06.27.09.35.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35: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=S3l07bbL; 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 1sMs5N-0001t1-UK; Thu, 27 Jun 2024 12: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 1sMs5L-0001p2-No for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:59 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMs5K-0004ZS-7I for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:34:59 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42563a9fa58so9513805e9.0 for ; Thu, 27 Jun 2024 09:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506096; x=1720110896; 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=R6Piulxoj8zPwW1Yv8YFFcFYZqBjXPSZ0pu/dRDGp6Y=; b=S3l07bbL8wEOFBG6Egt5VJE6JmoOuuP+AO3jZ+FFb8mlWGC0MPhAbkEV5mpNsXXYU0 ueli/iHLuYCRKuAmK8k12FKcN/DAUylcPTPyKLWFxOPUvNQnGB3xf4eJ1niXKGq7jamv qAMDWS8M4BdnrZQA4lR1WroEQxSRDKdZs80QIM3yZzS8HBUOobdJ9rj+Wz7kvis+clSt c9LaatXjIqZKG12+bHYKkS/UvUcx8/kMfixhXEGx+S+Dje/gjQYkmWX1oMHW9ApNkuj8 lTSGf3RFvR1VgBkL0jyVSCx4FsCkXt/eJeMqdVD4vFzjKlZxNQsHKZlWxorJmyOePJn7 /DEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506096; x=1720110896; 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=R6Piulxoj8zPwW1Yv8YFFcFYZqBjXPSZ0pu/dRDGp6Y=; b=pVBSjXZvRtRUpZH/wNQaO0GGGwsKPCtFFfPNK5LRYFdY0jTaQzuZlzqMgS9TnJ9SvD vnX4cMD2D9yCGAzFConKZbLZe6gG33C+xWMimvwVI032od3fHlDXAWwqHDSfJHaqYx40 cQjXvjbGToPq7PK17HMFwxopqVJ9QLH1mAuGU2hAsHZ6gxBNoeJFHjBuPTVyOMNdS4Z8 pyg/BH4+BznacLznsmO7OD1X0UnVcbhFxIYauIoF+QXJszCVS2ks+pOsbJommLIO0v8R gbJEF2brhg2jcAxaJwlS+Xd6Nosxx8qK59PSctIfyxJOgjePBLme3l/1bMy2hjJ+czvy 971g== X-Gm-Message-State: AOJu0YyWE02NKZTlMxlDk9zowenWVt+bTBwtvGBqLD8CIFJ0kxhnyyn1 isKamnrXTJJek9PoD+yy5lyHUY7MvLW9AcXxrU9myzswLx6oF5iyICHo52ZILfJcgH65lJd4ZvQ zsj8= X-Received: by 2002:a05:6000:2a8:b0:367:4dce:1ff5 with SMTP id ffacd0b85a97d-3674dce21f9mr1772490f8f.32.1719506096486; Thu, 27 Jun 2024 09:34:56 -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 ffacd0b85a97d-3674369eb17sm2371070f8f.93.2024.06.27.09.34.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:34:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 5/7] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27) Date: Thu, 27 Jun 2024 18:34:01 +0200 Message-ID: <20240627163403.81220-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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 b9c72a0128..bdd5f3486a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1518,17 +1518,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 */ @@ -2096,8 +2086,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 Thu Jun 27 16:34:02 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: 807840 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894611wrn; Thu, 27 Jun 2024 09:35:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXtqI7af9WAAVNJ93nHU0NMhZ7CwUd5xPlH9OH3MIhimP/XnLDpRsPY8bXNFwfBELwhXG/e3VKj5Y+XUu1ZVNjU X-Google-Smtp-Source: AGHT+IHdB4LZazGMW5mwCmc5Ft91cHMwtjKxnjX3Wae6QyRiGK86Kxhncti4fqnBiggqN+P9vHk8 X-Received: by 2002:a05:622a:1646:b0:441:56cb:98e6 with SMTP id d75a77b69052e-4463d26dc31mr38933191cf.4.1719506126489; Thu, 27 Jun 2024 09:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506126; cv=none; d=google.com; s=arc-20160816; b=HwqkRtDOMQcX6swkdfhGTv6mhdBVTpMndV2PO/WNBvZSfyMKdaU51/5QOBYxf92W2c f4UrQpL0YdKR0U05r8fmntBtAoqwwYd9uOp5jn0NAJ6FyTznUYQIIACSENeKCBNfptLm ysfT7ZopYk1hOnZD4zV0LLyjeERhZAR9ev3CzPHJC2eI2rSRU++ByLxovqQb74e2PSlh bDUSB92I9HZ2p55lWrRa61w23Es7Ly4zFXkHKv9umpjjeLiw1BCJ5qUtGrKkAgHFkm7P 4Y+w20pC0ItdNI8ynqoPp1DOPOZ3eMWgIfp8wB16d50Kp1YROyGDGIt3lC40xqYV4t4h 0ZCw== 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=a+swjnqxsHD9ZmAL3ZynjQXwZx/kNtJr6qmfanG6zVA=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=qpHt9XTl24SVh6By8xFZdPf11nv2d3DpP4S0PNCrMpurDY+9/fCrteKyIZclqO/cmp GKV4of6R6mv94ZDRMCuD6DulT9vQcGPjOlM9lEIXwv6VxNXH2Tds1zBgpev3d5Rc+Abl P9PmgR3gOE1prkQeTRdni4kWiJ0s0hwjiQDiCZqL6Mq76i9nK3V56qQUsL/6sYdQFHr5 q3477Zjux9H9pse4OaVV4c0T3d3pEOewDH52lHBoUPm5q5xcel1snHxdaRylZeBoRK61 F/Du+5z+XqzwzwTUk62k4yggdgmaq1Xrj5yA9EmbTSqkV+VgvQk3f6gSWt3fE8NfTjA1 8Exw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Emeu5zSI; 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-44641efe528si16632491cf.155.2024.06.27.09.35.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35:26 -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=Emeu5zSI; 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 1sMs5Z-0002WB-0F; Thu, 27 Jun 2024 12:35:13 -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 1sMs5W-0002HB-6T for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:35:10 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMs5T-0004mo-TO for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:35:09 -0400 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2ebe40673d8so95851901fa.3 for ; Thu, 27 Jun 2024 09:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506105; x=1720110905; 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=a+swjnqxsHD9ZmAL3ZynjQXwZx/kNtJr6qmfanG6zVA=; b=Emeu5zSIabq4XP6eST5d8z1OaaeWQi7dkn1RV409IFizg3EGbun0HUQd0TxAYyDLud QTuuVcMkHaxlVG0fE0F8Us7ZjkBtwZjIFHc4c5Fbx4981j5fKnffzGO5qKRnU9s+BX4M /sBr0OwsQJLGyQBgZ59Y4s9F8NO9wzdBBZQD23ANuf2mvu9zwhWQI2MbCnwFpNWUs5L0 QW686wJXvR31oa/XwO5Zqz/g9hpVcLHnxuFq0NPtqw78PfgYITzJT6dO0dEksMmNt+Nl dXB7qLXBZikxVlfrpjEpIiHuN5xtc2Tl+IUyGkymRhXvyez1cCnPSAgDsnSxqaQ27foM ka7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506105; x=1720110905; 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=a+swjnqxsHD9ZmAL3ZynjQXwZx/kNtJr6qmfanG6zVA=; b=NPO03oFtlUz7WRJrwR1P/NzOa7ZGDbCpHymxdpSpBrc3jkqZSgN76hHAVCzQHUvn65 MS+w1vGbAYkWIho9MjoQkwOY4hDDXwLGa7Dn6HS3PCaOnwUDgNFVm6NHUqHOv4Wg5+X5 YnyqwOKMO0nogz97UuO6Wt/crsFQRRkK/O5xPoiQn7+aZek2rlB7E+LHXYBMjP/qAor3 PzMAcG89iS0sesAZF90DIxaXt/5zydZC5v65N0FJnVbq4WyrCZRRoMntL2PVFPXTbS+u nTOTGlgQDSt3gxQuW31DlJ25MNqod5xLfKfncQrZ8nI0U/xqGXyZ8LDdAUqR1Han8tTi SISw== X-Gm-Message-State: AOJu0YxkBH09KdZFRLButoXBz/nq/S2eQAW6gwahD1eft+e89KOXmiGm z6tzOzm5PPOKGxkocGUbS+JNrlNg92p3M7fuKfQ2T1nUNwBYGtCr294b7R3Pz01F9l30v5aUz6S v22Q= X-Received: by 2002:a2e:b0f5:0:b0:2ec:419b:429e with SMTP id 38308e7fff4ca-2ec5b3180abmr84573371fa.2.1719506104865; Thu, 27 Jun 2024 09:35:04 -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-424c8251149sm72609445e9.11.2024.06.27.09.35.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:35:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 6/7] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42) Date: Thu, 27 Jun 2024 18:34:02 +0200 Message-ID: <20240627163403.81220-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::236; envelope-from=philmd@linaro.org; helo=mail-lj1-x236.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 bdd5f3486a..0cb528b0b2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1628,17 +1628,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 */ @@ -2109,8 +2099,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 Thu Jun 27 16:34:03 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: 807844 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp894823wrn; Thu, 27 Jun 2024 09:35:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXxH40NEPqTGJRv3TzCPE0nnfbZjHynDVVZoYB3TKus8LCNkTlLi2Ff6S+7ILL04+Tuqh8i1oCuWmOrc11Alf3/ X-Google-Smtp-Source: AGHT+IHupAbJPRH8Lpir2OQDteGCBGzx3dKymPYOalysoGbvrzrYXAgBfnzqvh5WLl1A+4XFQrfB X-Received: by 2002:a05:6808:120b:b0:3d2:16c6:651a with SMTP id 5614622812f47-3d545a7d56cmr16191950b6e.53.1719506158858; Thu, 27 Jun 2024 09:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506158; cv=none; d=google.com; s=arc-20160816; b=S+i/hdnYZ4CzlDLWVg7UDJdDUfDGse9smaRrEaclMjAKexNarTLRCjKIR2JTiEWJst +v3Um7RvG485fqL+DvjoBfF5MIhhOV2F4vl56N9H00Q1dwQHtq3TjtcU/SkvEumrkyG3 fHuYcCty4Oga4Msjz+bBWdIWWbU13dVgXnMTkjb6fGJj5ah6sdHcv+S1t5vh3fhkTDWE AGLGy8cd76XIuC3YWCX3DP8tTIoB1UyAf5Kd62yJth2K2pHrgyxRA4/8rD3A4W1zX+/9 rBh6uq/eUO7jqKMAKLl3vp/HwIBhcq90cYi7nQdwfLbRAygeCX/aLcDSOjZ6jEzOnA8+ +OEg== 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=lRVCvBojEsyxAg7JZRES3P5o6lr6YCg7S7r2PnPDGt0=; fh=Nuz+xfBuPB+jr462hD/XUDJnYvP1a+fdu4WocHfEOYk=; b=leFQBEYFd1gGfQdtamWixnX/uTj+LB0fY1F1nPbCBxvcjwDPqNttgwFybgOEV+iIW1 hXcetqxYcXO63k0mjsi1W/MFG5C5tKLBy6VrR1snVz/zVgBQSPjmgszk+n7NdAGHshaK +ePKHsldSEyJutsApNWuVeQa4hm911TDfuO8s8nGOg5ySZkTBT5kTPMvUt0TnjfFEsU8 gc1rVT+G6jxHaSA0UBL4E6NfiEJ0T5xRfTDbDAb6Qf6YjK7Pu0fUkHVquHsESvnZwdL8 kVsazKLenvAyyeMfNO0O2LCGAjz7xZzqcvReu7FeHZ3G3kYS9GXWHZsxtBwn9w/HQga7 /wdQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OHJusDm1; 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-4464221c058si15878341cf.657.2024.06.27.09.35.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:35:58 -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=OHJusDm1; 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 1sMs5i-0003gn-3T; Thu, 27 Jun 2024 12:35:22 -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 1sMs5g-0003Yb-Em for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:35:20 -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 1sMs5e-0004ol-IH for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:35:20 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-421f4d1c057so63818825e9.3 for ; Thu, 27 Jun 2024 09:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506115; x=1720110915; 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=lRVCvBojEsyxAg7JZRES3P5o6lr6YCg7S7r2PnPDGt0=; b=OHJusDm1jYbJJqnoTky0JjpTS6JHYNfwEdxtCyM4Y0n90VBg8hCUB20yPGjYySuttc BxLQJcXdCduLX/9PIgjaTueAv3Uf7qzbIozr2L0DFHXi3BBAkmhbDen5/6FupsGPY/1Z kHdE1XM5Z6iQ03dtXNuANgBotbFLm7FQaqNeOF0nmdJeXDx2RbKLVzrrgAlLTP2oV7rI Oq/AWr8v1rxF2TVQOuvUm1Sl67dSmKIwrPHaEPjKU7ZT/JV7LkVyLiRHh6JK/C4aaZbV +5gq1w4VirPcKgEmQWvL3RCYDcRPXCiozfRq5/tJl1ANjAh08kmbhpmCK2D7DIvyiVdh 8Uew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506115; x=1720110915; 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=lRVCvBojEsyxAg7JZRES3P5o6lr6YCg7S7r2PnPDGt0=; b=orR9DZZtK780za8VLbllDVSM5KRoU0Xm/vkj06dYklkht9W2SZqVyQtqU7p8OHmNWL VzUe7jOq0E8dFzVyJ9lya4KNA+TXAq8Cgi/xcTiFaIGFOke/T2byMixbW4Hgk1XaWFKB M7F/2QQbjeClgYj+6KUZk0ZojDSaN2OBJTiXL21YIUr3KUiYcNm6D6nBu9KoYeqENlf9 sbqliUDlOcxS7JgJYWPcEKvnIhpACduFQezZ+7Y/XTJGPfQG9yqrOeBB60C5gtEk6WyG Zaxz4X9Xx7p9ocUWXdJtlXorgz5D+a4AAtKnZN7HpF5Zi8IPJiWVoUf6oqwMqJEUHGaU cZlA== X-Gm-Message-State: AOJu0YyUqmpMqlPpVbMn4Idjyd/wckH7AaHDc6IjwoUlyoXzgMH7GxTW ukh2WpfD3k7v75bqGKqjVYM1zHN3WYqooMUy1DmK6cBI3qGrTChrAicgt8i8wMZZ1E8v/MUWHfy IS8Y= X-Received: by 2002:a05:600c:26d5:b0:425:6262:1cc2 with SMTP id 5b1f17b1804b1-42562621d7dmr25305875e9.34.1719506115535; Thu, 27 Jun 2024 09:35:15 -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 ffacd0b85a97d-36743699b02sm2397663f8f.85.2024.06.27.09.35.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:35:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Sai Pavan Boddu , Luc Michel , Francisco Iglesias , Bin Meng , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Joel Stanley Subject: [PATCH v2 7/7] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56) Date: Thu, 27 Jun 2024 18:34:03 +0200 Message-ID: <20240627163403.81220-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163403.81220-1-philmd@linaro.org> References: <20240627163403.81220-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=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 0cb528b0b2..f9708064d0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1657,14 +1657,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; @@ -2109,9 +2107,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;