From nobody Mon Nov 25 02:46:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719508465; cv=none; d=zohomail.com; s=zohoarc; b=iMZepszDO+ebBbbqPihcwjEgMR0sPLNKaRKybru+QOIAngErwnuCbz+q/rhVQV8Wi58xFbQaqpIC9mXI7VGXFsPIC5aO4NYsUVkFJyvK6CZk3nqVPXEKAajHMp6Oyzxnysw8Dx4Hw2j7H3zoQU2lUHzyYaJukOmSn5Sl4+LIZ1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719508465; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L+wEPWvr7kf9AKn0k2ofydQW0/V6lPt4e04Ilr1xeQw=; b=iZaMRSQ4nD5iTr98EXof3cr9qi7YFumQxiZGuvyIXg4bHInIOvwJktkUVYyKpVpgt/lX+sFImbSD4E7lAftnMtkwHoBpH5zx38LLedggIhTmk0F1/xBaFPkYKIpdUcBEx76QrsJFxND+0dqjnOBVSmtq7juehy0r5g0kYa2/4hU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719508465935611.6607721852056; Thu, 27 Jun 2024 10:14:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMshQ-0007YS-8v; Thu, 27 Jun 2024 13:14:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sMshN-000750-5D for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:14:17 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMshE-0002jY-RB for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:14:16 -0400 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-52cdcd26d61so6523716e87.2 for ; Thu, 27 Jun 2024 10:14:05 -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-4256b068d53sm962875e9.22.2024.06.27.10.13.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 10:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719508444; x=1720113244; 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=L+wEPWvr7kf9AKn0k2ofydQW0/V6lPt4e04Ilr1xeQw=; b=qwuOxiGmSLB2LCy6/0mroM6vcAJyi9fyO9LMHjJElLzDPwzQryQD1B+QZ1bsPta2OU vfGtQjMG61sV80jp164frZ+HXI5iXsUY95Iw/01zrxdgMZjpjluP9p9KYdQpW9LoAq3+ d+r2S9nZiVXpXvUdBOkSpeHQTCMjn7TdUX+0RYQLSU5n5VAe5r0TGpAjfP/SoEjo523B mLj4IehunLhgcveWK6dHTihT7/X5sQitERZ4GBhCWoQCfQifkPGuMpcXSttpR6ZozIxF pdN5gYRQKzInjhCC0/fjKslMY1R9uBKyyGktiQ+Uz3CdPcTYgBsYIL6zVW+6krIBD8gV WxOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508444; x=1720113244; 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=L+wEPWvr7kf9AKn0k2ofydQW0/V6lPt4e04Ilr1xeQw=; b=qF0w+BfexgS/46NmG35/k26vPaQWhpVCzcoO4y6Lfaf8dJa9PF9M5UDbtC+I22sKzM K7Qu7NI/QkDPCq7JFyKwwoNDcsARnNikufuAszLZuPlM5+k1muDyBo/VvqfGz7NNptde M/jiIjMTqoTs7Ru3GBzkcSbpQ+MQLfrQf//7VP4GnG7Ho7e3OzBGHdwVTW7F0M0iDU4y do6538sXvv4YtgLpSJrcfhDugN3nqOdzOzurPAXDBNG590sYxdoD3OdxnUfEmE5s0SQg lAu0ObsDo2jhX8Y9UzxfHjT2FJwTXzgbJqefELei2pZhaPzHKUakYLO+KCqc1qqPUSpd 0X4g== X-Gm-Message-State: AOJu0YxO9BH3WREkZ7EVLOfUFJ6qLc/dCCHW59FREHwORX8PWYKad2BE gSe2zA3ql6CUuXyaajLEcf0i6CSRaFmyM1hapIXQDAcmSqKNY2GaMjoYwf6hvO6OxTJouz9I55N sLuo= X-Google-Smtp-Source: AGHT+IEUo4kZjjowsGek3Ddkn8CnG2fpc7xcS2MUl3CjnybjD0PPleR4nZkmuxfTvz0gfFCV2cynig== X-Received: by 2002:ac2:5dd4:0:b0:52e:7542:f471 with SMTP id 2adb3069b0e04-52e7542f5b4mr804494e87.29.1719508444158; Thu, 27 Jun 2024 10:14:04 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Joel Stanley , Luc Michel , Francisco Iglesias , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vincent Palatin , Sai Pavan Boddu , Bin Meng , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Sai Pavan Boddu , "Edgar E . Iglesias" Subject: [RFC PATCH 16/19] hw/sd/sdcard: Add mmc SWITCH function support (CMD6) Date: Thu, 27 Jun 2024 19:10:56 +0200 Message-ID: <20240627171059.84349-17-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627171059.84349-1-philmd@linaro.org> References: <20240627171059.84349-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::12d; envelope-from=philmd@linaro.org; helo=mail-lf1-x12d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719508466203100001 From: Sai Pavan Boddu switch operation in mmc cards, updated the ext_csd register to request changes in card operations. Here we implement similar sequence but requests are mostly dummy and make no change. Implement SWITCH_ERROR if the write operation offset goes beyond length of ext_csd. Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ae5e73175e..e7d8b9c0fb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -625,6 +625,7 @@ static bool sd_req_rca_same(SDState *s, SDRequest req) FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) +FIELD(CSR, SWITCH_ERROR, 7, 1) FIELD(CSR, READY_FOR_DATA, 8, 1) FIELD(CSR, CURRENT_STATE, 9, 4) FIELD(CSR, ERASE_RESET, 13, 1) @@ -1075,6 +1076,43 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) return ret; } =20 +enum { + MMC_CMD6_ACCESS_COMMAND_SET =3D 0, + MMC_CMD6_ACCESS_SET_BITS, + MMC_CMD6_ACCESS_CLEAR_BITS, + MMC_CMD6_ACCESS_WRITE_BYTE, +}; + +static void mmc_function_switch(SDState *sd, uint32_t arg) +{ + uint32_t access =3D extract32(arg, 24, 2); + uint32_t index =3D extract32(arg, 16, 8); + uint32_t value =3D extract32(arg, 8, 8); + uint8_t b =3D sd->ext_csd[index]; + + switch (access) { + case MMC_CMD6_ACCESS_COMMAND_SET: + qemu_log_mask(LOG_UNIMP, "MMC Command set switching not supported\= n"); + return; + case MMC_CMD6_ACCESS_SET_BITS: + b |=3D value; + break; + case MMC_CMD6_ACCESS_CLEAR_BITS: + b &=3D ~value; + break; + case MMC_CMD6_ACCESS_WRITE_BYTE: + b =3D value; + break; + } + + if (index >=3D 192) { + sd->card_status |=3D R_CSR_SWITCH_ERROR_MASK; + return; + } + + sd->ext_csd[index] =3D b; +} + static void sd_function_switch(SDState *sd, uint32_t arg) { int i, mode, new_func; @@ -1398,6 +1436,19 @@ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState = *sd, SDRequest req) return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); } =20 +static sd_rsp_type_t emmc_cmd_SWITCH(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_transfer_state: + sd->state =3D sd_programming_state; + mmc_function_switch(sd, req.arg); + sd->state =3D sd_transfer_state; + return sd_r1b; + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD7 */ static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req) { @@ -2602,6 +2653,7 @@ static const SDProto sd_proto_emmc =3D { [3] =3D {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_= ADDR}, [4] =3D {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] =3D {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, + [6] =3D {10, sd_adtc, "SWITCH", emmc_cmd_SWITCH}, [7] =3D {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [8] =3D {0, sd_adtc, "SEND_EXT_CSD", emmc_cmd_SEND_EXT_CSD}, [9] =3D {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, --=20 2.41.0