From patchwork Fri Jun 28 07:02:05 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: 808243 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp226687wrr; Fri, 28 Jun 2024 00:19:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVNoveEuEZ7AsyfUoygpi3ihTTHfq7r3JgiPHW4gwsbEJKOfk0HOhr7r1qKAox87HXzZEgFwxIpqsB3CcsPXoYa X-Google-Smtp-Source: AGHT+IGMBLrurdGFjXPKJXHxLlRaG34shdOe4sW1ziI7Uer/zmQrgYtEs4FwivW4nc/ZG/MgZmIH X-Received: by 2002:ac8:57c5:0:b0:446:4a66:bf23 with SMTP id d75a77b69052e-4464a66cdd7mr33202231cf.1.1719559188389; Fri, 28 Jun 2024 00:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719559188; cv=none; d=google.com; s=arc-20160816; b=rU4nmQgsukyfmdVLaTFK4uZ8bEFbp5SEXrN7BG7JrSTI199Gac/P8VrjfkJIXcfMX9 mzBzaquZPK7CuSYvFOEodHhHXEKl76opUlg+RAyXaJMXxty34GjQfm+6uWrr7eyDk2Nq Te9LIsUFByHs8dtg+yeRelxe5LAmksEfIVIGfgmHyGEkdgPeSVtln+MMb9g/ffHAlj5t U3wB6/MVd1DaaUbW60W9AZaxNZ5UYrV1AEjnmx1anqJHX6YlVyH+MI9E5RxSVB45G4H3 pppV4YuBYvrWXCLWbuW/DcXMOaZoJq7vLE9eLH3RApsh81PMDyAQCAaKE8VecVCA2JnQ dNMQ== 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:to:from :dkim-signature; bh=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=t0WVSzK+c/Xio7tyCexxhl+Z1nN34+h33Cft3qdm50sISHsudHCnSTuQJKAMN8hH/U E1hpPeX/1jkZBvExU199/Ut+l2mKsq6gfj50lhCIhDAxyNFPIy9VDN4/mzDoUGExya88 mSfVATFRhUBQZ1t7gOBP4aJLNCFUKFMD/f1eCcxeGxDerFLMyMuIbj7Wx5akfpbf7a5m ADyIMRoQvove7mGaFLEnQ9TNPZTyzVVq78SYSbli1zvdfKpfksPk9wvlba+oaW2Em9MB unaphbtl0XkGi3DBad8uMCdGt+Tf29vYo98p4iwzchpHegGs2ZOxwXK/dd2sRIIhl68i iEEQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vBFKZg9y; 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-446514a1f18si12722671cf.459.2024.06.28.00.19.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:19:48 -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=vBFKZg9y; 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 1sN5l6-0002BC-Qx; Fri, 28 Jun 2024 03:11: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 1sN5l5-00028I-57 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:10:59 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5l3-0004rL-Ar for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:10:58 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4217c7eb6b4so2651725e9.2 for ; Fri, 28 Jun 2024 00:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558656; x=1720163456; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; b=vBFKZg9yWrwn9UklzAlj1ewb5WKrhLJ67KIiLiI0uSUDhOBGMLqbnZoYClxyk0q2np QM+DNdHHd3AqmjBxSPdJnQTUVmVnsedPEhh3RXLpyPCX4k1z6t5RirVzE54W3whFd6A0 WUMxO7jBpON7fZq0i+E4lg+hl2bGQXxmnSwlGEtGRLv33ue/O2j9GwvTPFZVGOMGQXnZ xFW89DkfZHK6irWAFU1WhAgB/edlzcpw456zb46A5mKZqAF4rT0t8I0UKZseI9RaIBX/ c63kfoJ9nY6mei3lOgrdv5d+NTvTaYH0x1Hwzm4Ao/qZEnT4j5gTPQoOkn1WwbJHEflE PIgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558656; x=1720163456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; b=L3Cbu0g2ljWC201SAdzKk2vAtmmsN6jsZhJKAj3UfG68J1ky4woa9M8/2ZaWdRgc+T +oHPkqM6IRd0hLoFAXfuDRik8pJBen6YOjEdr2zh98I2H4xkZOWRduIFRQsOEl5p0WMi zSTo0mLpYBjNPy6qSk2gcRo4Vk9n7v5+f80CyEKrXedS5a9WkfqxuXVBPsCQR5UO6mNn WManyVdSQ/toAMZUwrGJ09YmXlIENebxNk+IuIrrpW0Deoq0iM17ODPa4UrNfFLdIUcz 3yGqPOcMhuuQ4CdLOBwv7hgYkjuFnEbqXWxWTsCP4AvWkxR6DtigbdzbQ/qsr5/KMu22 mFOw== X-Gm-Message-State: AOJu0YyZBBl5E5qDqYjkQuRMknCeFqJGJ9yBUdwinqD8fQW4TAqulqq6 adP4+ozCcAqJxksTzj641yF3fr3XZPiuqXd/ot9wqpTZWYDIWTsI40T7ejhbheVn6evKawxH7FJ 0KrY= X-Received: by 2002:a05:6000:8f:b0:362:d382:2569 with SMTP id ffacd0b85a97d-366e95d7df8mr9578972f8f.44.1719558655726; Fri, 28 Jun 2024 00:10:55 -0700 (PDT) Received: from m1x-phil.lan (cho94-h02-176-184-4-239.dsl.sta.abo.bbox.fr. [176.184.4.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d9286sm1343699f8f.35.2024.06.28.00.10.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:10:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v42 89/98] hw/sd/sdcard: Implement eMMC sleep state (CMD5) Date: Fri, 28 Jun 2024 09:02:05 +0200 Message-ID: <20240628070216.92609-90-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628070216.92609-1-philmd@linaro.org> References: <20240628070216.92609-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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 From: Luc Michel The JEDEC standards specifies a sleep state where the eMMC won't answer any command appart from RESET and WAKEUP and go to low power state. Implement this state and the corresponding command number 5. Signed-off-by: Luc Michel Signed-off-by: Francisco Iglesias Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0f9bab105e..bd77853419 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1182,8 +1182,19 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { - sd->state = sd_idle_state; - sd_reset(DEVICE(sd)); + if (sd->state == sd_sleep_state) { + switch (req.arg) { + case 0x00000000: + case 0xf0f0f0f0: + break; + default: + return sd_r0; + } + } + if (sd->state != sd_inactive_state) { + sd->state = sd_idle_state; + sd_reset(DEVICE(sd)); + } return sd_is_spi(sd) ? sd_r1 : sd_r0; } @@ -1246,6 +1257,30 @@ static sd_rsp_type_t emmc_cmd_SET_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD5 */ +static sd_rsp_type_t emmc_cmd_sleep_awake(SDState *sd, SDRequest req) +{ + bool do_sleep = extract32(req.arg, 15, 1); + + switch (sd->state) { + case sd_sleep_state: + if (!do_sleep) { + /* Awake */ + sd->state = sd_standby_state; + } + return sd_r1b; + + case sd_standby_state: + if (do_sleep) { + sd->state = sd_sleep_state; + } + return sd_r1b; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD6 */ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) { @@ -1648,6 +1683,7 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req) case sd_ready_state: case sd_identification_state: case sd_inactive_state: + case sd_sleep_state: return sd_invalid_state_for_cmd(sd, req); case sd_idle_state: if (!sd_is_spi(sd) && sd_req_get_rca(sd, req) != 0x0000) { @@ -1969,6 +2005,12 @@ int sd_do_command(SDState *sd, SDRequest *req, req->cmd &= 0x3f; } + if (sd->state == sd_sleep_state && req->cmd) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is sleeping\n"); + rtype = sd_r0; + goto send_response; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req->cmd)) { sd->card_status |= ILLEGAL_COMMAND; @@ -2420,6 +2462,7 @@ static const SDProto sd_proto_emmc = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [5] = {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID},