From patchwork Wed Jul 10 14:14: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: 811781 Delivered-To: patch@linaro.org Received: by 2002:adf:ee12:0:b0:367:895a:4699 with SMTP id y18csp775551wrn; Wed, 10 Jul 2024 07:16:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV9Ogckv8Kg84DMl31s5HGGq99UXCPIJjSL1L1uw0VfMUjhMQd1xU3Ay/sPRL/8fhrfcfROI103QiNjkb2VbEZ+ X-Google-Smtp-Source: AGHT+IHJJoikXKXbCpnnCrsB5TCrrTUJauFsUoFEqDtuuTEJ8PykNeWzUApFEwPp7pK68tebZTyd X-Received: by 2002:a05:6870:168c:b0:25d:6411:a0af with SMTP id 586e51a60fabf-25eaec6d8a0mr4292658fac.49.1720620972875; Wed, 10 Jul 2024 07:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720620972; cv=none; d=google.com; s=arc-20160816; b=bK7VN7E6uil5zEFsFsGyaSWVCOaZRS/MQzTuy2GPG185DJAoOvj0f10YROWG+z9JNC Js1mZf2cgRYxwZgT9JY3sAtCkaap8l9SzrHOtsrS0PbXZ0sw9JgcQWmBRF0TeT0heRNl A3roaQV/l6rp5jtf5Bhmn8WB1IzWxnETv3MsSCmERrv50JXRiBrjxFJhkkQVbRIhIalG QsEuyUWuSumSESmMzSggXile8D37Vw3++U2P23pv39yd0Sqs6qNTWN4dmHRDiK9zVi3H I7CmzVM4oxWI3FEfzXACZEIcRATsXDFEm8ESt8INVnfEsUl2fFU7wRmc9qwavepQ4+IC uE7w== 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=MdllFDvAAAapWc9IpfzuQduI83NS5VUSC4hX+cxnlVQ=; fh=eI8N6o5U11RIgdEbhF9aLRajXTUvSXR3iDLpmaRaPIk=; b=XKvG1guqpXUFZDNyEytDahIQFryleDjCZVUu3ALrgTV2TFJR5m77QaMCqwD+WwKLgn ZzuDj3a7u8S0h5umKD4eu367TcgbtATzc4gNlwb6R4+vbF8u3Cu5AKcxx4MyyntSeR0d APS0NjSIdG85Xatgsj1QKWeoNAMkDQ67foV0m2eEfXe+9tI/sfVfnmMVc+Db84Eo2zs/ rdJkU/Dfa6HcvwjFdBTd+slsQo2O4tTiDLcz+04Qe/P44uXcFMkOcJLKLYbaSEoit4RO GmW7zXZdM/t+4Jk7B+0KhZbb3Mua+pV0UmkuGQszU7P+Keo5dJbDEp0SgMaGAOmm0dD/ jZEA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ITtBZ9IL; 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-79f190a1c83si461095985a.258.2024.07.10.07.16.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jul 2024 07:16:12 -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=ITtBZ9IL; 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 1sRY71-0003ys-Qb; Wed, 10 Jul 2024 10:16:04 -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 1sRY62-0008Il-Td for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:07 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5z-0003zW-IJ for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:01 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2eebc76119aso15808781fa.2 for ; Wed, 10 Jul 2024 07:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620896; x=1721225696; 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=MdllFDvAAAapWc9IpfzuQduI83NS5VUSC4hX+cxnlVQ=; b=ITtBZ9IL/y7oWbbPMgltYBk+YJ1xs0mclnl70ur1403UXjtrHUx/E+uRe/LhVZkhf8 tkteQ+9Ycd8fX91Qc737yrksnrBUJrOk6cpb2Ks/YBjwWThCoOqjy1jib6oP8elXXQj4 36d10M+AwO0znbTxqOQPbpVlqKzSfcHAANUE8CFtmt4sLVzo2k3ICUb2pnFQRw0R5OFw nDNOvKCcQ2APBYRlGpa/zTYAFqcLQEZVrNGPPzlXCJS3Q74ek9MP85/QR/+QQgcHnfEd CKGfJCW5x0J2i2UPiiyLkXJ3EVN8YQOv/KGuYv0ERyAmHsyygWDv6WV3SM/Tplo/mHoR sC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620896; x=1721225696; 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=MdllFDvAAAapWc9IpfzuQduI83NS5VUSC4hX+cxnlVQ=; b=iT4tepzz6KdtYGHzakVybXlYcWno3SHGHE5g3EnmcXufI/ffqP3QSruPglnpJ2EOzT mxdFavcXnJPo+TL6U9yY7BMWCp1CD0Je+7jOZIjF19atldLquJz8nT4AqbUjEuDS5p/d omg6mvXhSdO4/ZAP/LmtPlQSIkdSrMYelPJI4hqA7DkXZGIVJIHH9+vRlv59tdZK14Qa p9GPi2HQ2d0MI33WTJcVQCeaYzfZu5+e19rXyLrqz90gkHC2GRhg0nbvzaZ/dTleVMHi Ju/sh1ihHwXE3nYwOx1RtXCuTwQm4s4CEoNBTq31gXTdVX168+72lIyYQYEutQgI6UwW 2Vnw== X-Gm-Message-State: AOJu0Yycj1ncaW+mBETJ6fScd1aiAeD2DIw3gl/KmFwblujC3sQ6jFho N913Nmn7jty7dMrO0S/TsDp782nk5ugxSPT/QzEWTujbteyXOr2+PMcS2QKJxVCCMoPFR3SWRE8 A X-Received: by 2002:a2e:b0d2:0:b0:2ec:556f:3474 with SMTP id 38308e7fff4ca-2eeb318b5demr39410081fa.52.1720620896236; Wed, 10 Jul 2024 07:14:56 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266f7430ffsm84124195e9.44.2024.07.10.07.14.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v48 07/12] hw/sd/sdcard: Implement eMMC sleep state (CMD5) Date: Wed, 10 Jul 2024 16:14:03 +0200 Message-ID: <20240710141408.69275-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=philmd@linaro.org; helo=mail-lj1-x233.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 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é Tested-by: Cédric Le Goater 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 3628686832..cf130ad1e3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1236,8 +1236,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; } @@ -1294,6 +1305,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) { @@ -1696,6 +1731,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) { @@ -2018,6 +2054,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; @@ -2467,6 +2509,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},