From nobody Sun Dec 29 00:47:26 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719559187; cv=none; d=zohomail.com; s=zohoarc; b=TjNwLGmhmvb02FG47rAe2Lyl6juJajJxVPz26GnKCGA0lR+r7xfmT/FX45SWo7vJKzpwgI4ORXAHohgnfKDG9QD/oB4K3N2H1aV2j7AgkR2d1RP0DmUVdwSaL7w3lL3b2K2S4NFIzzYxBxnbpLRGn6i6d4mtLMaCa5ijACjexP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719559187; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; b=Za9LnHSTo2da9dy4uxHJWJvitpjewemGsmKD84i122sGM3IfR/XRhGyUFhC//NwSkPeeOLgRfmTFVxojvlUiHjVsXZKGfxgVxjD50SUWA8Bk42w99T5DuD4KcOeq1iBjDIfMy9NDV3SP9xRM6/mwDmvDg6Cn2VonRVjUFF20XZU= 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+importer2=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 1719559187899613.8510171441409; Fri, 28 Jun 2024 00:19:47 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IHrK/w1lYcTETVwtc36uZHECNoYx9P/rab/5V4VlzexCLUTOz+Yv3iLP9sbdqJp95agIw+ocg== 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= 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 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719559188703100002 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=C3=A9 Reviewed-by: C=C3=A9dric 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 =3D sd_idle_state; - sd_reset(DEVICE(sd)); + if (sd->state =3D=3D sd_sleep_state) { + switch (req.arg) { + case 0x00000000: + case 0xf0f0f0f0: + break; + default: + return sd_r0; + } + } + if (sd->state !=3D sd_inactive_state) { + sd->state =3D sd_idle_state; + sd_reset(DEVICE(sd)); + } =20 return sd_is_spi(sd) ? sd_r1 : sd_r0; } @@ -1246,6 +1257,30 @@ static sd_rsp_type_t emmc_cmd_SET_RELATIVE_ADDR(SDSt= ate *sd, SDRequest req) } } =20 +/* CMD5 */ +static sd_rsp_type_t emmc_cmd_sleep_awake(SDState *sd, SDRequest req) +{ + bool do_sleep =3D extract32(req.arg, 15, 1); + + switch (sd->state) { + case sd_sleep_state: + if (!do_sleep) { + /* Awake */ + sd->state =3D sd_standby_state; + } + return sd_r1b; + + case sd_standby_state: + if (do_sleep) { + sd->state =3D 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, SDRe= quest 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) !=3D 0x0000) { @@ -1969,6 +2005,12 @@ int sd_do_command(SDState *sd, SDRequest *req, req->cmd &=3D 0x3f; } =20 + if (sd->state =3D=3D sd_sleep_state && req->cmd) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is sleeping\n"); + rtype =3D sd_r0; + goto send_response; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req->cmd)) { sd->card_status |=3D ILLEGAL_COMMAND; @@ -2420,6 +2462,7 @@ static const SDProto sd_proto_emmc =3D { [2] =3D {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [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}, [7] =3D {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [9] =3D {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] =3D {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, --=20 2.41.0