From patchwork Thu Jun 27 16:27:19 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: 807826 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp890958wrn; Thu, 27 Jun 2024 09:28:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWLGNID0UsISkAGWW8zVPof0D22mfT4scDF08T+7D8gKYBBsF8J0n39RLq0MkLxen+5nai2D7tWxKLazDobH4Wb X-Google-Smtp-Source: AGHT+IHkGPmewEsJn+0eOuw4w8vODh+SvoWRbkMVCnAMY7zxuaOZ7oJE4FESThvkXON15H9A9Cpq X-Received: by 2002:a05:6102:41a7:b0:48f:95aa:ae2b with SMTP id ada2fe7eead31-48f95aab13fmr1887578137.28.1719505690440; Thu, 27 Jun 2024 09:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719505690; cv=none; d=google.com; s=arc-20160816; b=qhp9A51l/8U/esBNneYK+TKVuizj7oB8m/SHBawos+3KRnOqRvpSlewvmxzrZ/EDtk GnoZSwC73KY348mioK2pYsMHq2W28W9Xq7PqtpqScL2xeDhAfkSONbA97MJFWUE82kyw TggpV+GeOfSFOIOjb7jquGlei1o1CP9Aw4/kkXfYWFqdh3ME1bgDPmcRZLGZCX3DEIkp kF96BBDIV9BRxQmZfg74D2rfQpX0ginb0JED9hvA5iqHe5Nq8u8Na23SiM/t2kTvDRgo ISYqNF+ddUg8wMV7mm1PWnyW8IT74UwYijZQhcPjNu8WpD8TstmTHjDXkS555hyPVTMQ Lyag== 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=/dkdp8a0v1eDrwEVEV8e/ROv9nmNjtoGPC9rjoBe3Zg=; fh=CQ9QAhiPZZ1APu1JLxgbtxAnzrroUJn9RCDrjAjVXrk=; b=SLEG+iV8lPriYWMrci9E/pQkWvp7ev7sRByihDhpY1iiMmog8wQcNoLWQ5LBf73jho iHkeztSovvdC5wA8Bd6DVz3db5hczCEWaQSTJYg+5MNTO0kpRXVmm7eweA2txAzSEpL7 aPJeiLO/qQhEmSczJPXUbFq+hQziZj3zgGXwSu/FpPhYWFTGEt6D8UEWaxk6A8KZHS9g sTdiivsWpGvn6SFAAr65wBsIeCqH8h+6QmjezB11Qvqo0DQV2dwGbiVZGkA7G5ft9Fap tA/CVM0p4VE0Vcd8o0eve29TAeOUUms4VmyJqwjrLm6DGBXsIJ2Xiop8htMzyZw6WbaS mH0Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QEeCDpnn; 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-6b59e3637dasi89386d6.94.2024.06.27.09.28.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:28:10 -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=QEeCDpnn; 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 1sMryT-0000YW-NI; Thu, 27 Jun 2024 12:27:53 -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 1sMryR-0000Vy-58 for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:27:51 -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 1sMryO-0003Le-JW for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:27:50 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-36743a79dceso553688f8f.0 for ; Thu, 27 Jun 2024 09:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719505667; x=1720110467; 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=/dkdp8a0v1eDrwEVEV8e/ROv9nmNjtoGPC9rjoBe3Zg=; b=QEeCDpnnxzodhiI+YlDudza8dfO+H9e5eSCLHeZz59J+MHjRKF4sWK3se+ydq8Or2C WEUuYsatW0ekNd7OhYsx9d9Rc82dVtc7dLywp0nBVSCeO+hFm6YxxJmcVWaxENWToTr2 3megdtH1bibyKptzl2IOTpeUhivUn3Tn3P3ydNS1b/19FUTyK3Ie1QabYEZkT4QynO8i KPESup6Uzhi0Hs06df7W2FRGIDt48Phu0DhnO9/4gHn0hdq2dpA/cErr5MF8heRFDkZl P4R7SkBUrgp5lYb3OlqhjWbZUowAaV3bf210uzkhL0YgNrIKcq+HpjNVhUeAJBA41XwE AWpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719505667; x=1720110467; 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=/dkdp8a0v1eDrwEVEV8e/ROv9nmNjtoGPC9rjoBe3Zg=; b=sgrGIlhSPTT1iTP8GHtYyg1uGAJAoCe48lauuXAru4xGDJvs/C0wgQPJyqFPkliGEF ZNUECC/0BuexGCutMjA5ZBcNZ+oJNxRC0PbAJIVpyqaRuFdd38UrAcN/q5juEPVg/tas OMpVzeziD2yB7wIpe8VDsdBk0VNg4jKucV3Sgca/vg2I0r6Dw68hrJktOaVs1Hcapg06 n5erdQNyMkPgzb1UeLereTJqUsZV990b4BWkUaSNgwQoYew6KW1UhuFVblFGwvwUDM5s k91o25UWf3+n0kPAtL4IjWblXgD2BCGnoIVaS/Fidm4Yk0Kz3hAXsmhTTwgESJCPFX07 gHBg== X-Gm-Message-State: AOJu0YyuoUPIH7PJ1uY6MwLK7C1zzPxv5wyiiwz/Sv0X3jsKgJdJEXgf joXIhld2k/IP4LVTnxKquDwNTSn/UcrbaOBZVDeb+oFZjzH/fgRg91a/kB1LM4bjUc7bXt805KD pAgM= X-Received: by 2002:a05:6000:1748:b0:362:363a:9594 with SMTP id ffacd0b85a97d-3674178975cmr2208517f8f.11.1719505666928; Thu, 27 Jun 2024 09:27:46 -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-3674357fcb2sm2379487f8f.30.2024.06.27.09.27.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:27:46 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Francisco Iglesias , Bin Meng , Sai Pavan Boddu , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Luc Michel Subject: [PATCH v2 01/11] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte Date: Thu, 27 Jun 2024 18:27:19 +0200 Message-ID: <20240627162729.80909-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627162729.80909-1-philmd@linaro.org> References: <20240627162729.80909-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=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 All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers: - sd_cmd_to_sendingdata() on the I/O line setup the data to be transferred, - sd_generic_read_byte() on the DAT lines to fetch the data. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d85b2906f4..1a8d06804d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -142,8 +142,10 @@ struct SDState { */ bool expecting_acmd; uint32_t blk_written; + uint64_t data_start; uint32_t data_offset; + size_t data_size; uint8_t data[512]; uint8_t vendor_data[512]; @@ -1083,6 +1085,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, + uint64_t start, + const void *data, size_t size) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset = 0; + if (data) { + assert(size); + memcpy(sd->data, data, size); + } + if (size) { + sd->data_size = size; + } + return sd_r1; +} + /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { @@ -1920,6 +1945,20 @@ send_response: return rsplen; } +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte(SDState *sd, uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + + return false; +} + void sd_write_byte(SDState *sd, uint8_t value) { int i;