From patchwork Thu Jun 27 17:10:50 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: 807889 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp913537wrn; Thu, 27 Jun 2024 10:13:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUq0+vDxKIxc/x7yscxp58mWM7NYgdWWBVb9QYhpRaOMPQT5smCgAtUomThzQ8MKQyHcoZYi8KQ1nQEYm7A7nXp X-Google-Smtp-Source: AGHT+IHn/Bv8Yq6MDW3zXHXfJLw2cCjR6wCreDYcbg8RmWoi5wJ/5yYFenlXVPzsuUF9kx5x2hcG X-Received: by 2002:ad4:5de8:0:b0:6b5:45bb:6b2b with SMTP id 6a1803df08f44-6b545bb6d7fmr160716526d6.51.1719508382174; Thu, 27 Jun 2024 10:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719508382; cv=none; d=google.com; s=arc-20160816; b=J1s/0Q2cSilC0MvLFH0Ey5f+YCrOMovF/17ye1DyNt9Aee/bJxK0IUVePjbJX3pHYx hyUIA17bITW1Z7sEK2UNQwEqF0Qbh7LEi+ReNudYRnYuhMQDzceWwDVtJL6wC16sYX5p 64DqWqxyqt9lFwnu4Y6e432lMzdcP6Ayz8OxZ4twP0qHtvROA8I41Fr85VhfeQxizzUA ufFyfVPwYt8lLBZd0ro/qiVerZbeYOnphShk77U3YT/JvRaf094HOy/33OXocndvPPlP DobuxLOZ9UWWArp8wOj7VR4oCJNIMEYmwnwgwZe7GSIpSSpAWC3Q5hILJs1RZnOIN0+l dZxw== 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=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; fh=WUqfD5CNolTLXU3odpyK/irI96uSRBSbw3kHmNv9290=; b=wGOJz5ILreReZ0vx+HzrLsLsOJVXafCO1vczqJ5cbNyMfi/FFUUe/jwju3anriE9qn zLDFNjjPTi4RFrVwvQa+zF+jI5TY4oIAc1jgHkqIp2VCdeJST57y1ckLedJ8kdBB8ps1 YpfXMJ9ZKWIfBvdaXR45Apk4F19YBmf6mRjUmtUCn1XqzcVIE/VKfYCyzbf3jar/r/va RJ1HZljL+0sPM5m1l1auYgWkmdk+4s3FauMUtOjZCpVJe6D87jd+KlR3rnWUYZqdOn1E abpQAtLQNTIbF1VdDMNAlUAptRmK2qNaBEf9o6qzJjvRvP6NwEPjzAgbrjZpJ5o9pfJQ Rg8Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VoFIIkGq; 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-6b59e5eb435si681296d6.351.2024.06.27.10.13.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 10:13:02 -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=VoFIIkGq; 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 1sMsg7-0002Pe-Kp; Thu, 27 Jun 2024 13:12:59 -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 1sMsg6-0002GE-3I for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:12:58 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMsg3-0002LF-PS for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:12:57 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cdb0d8107so8315382e87.1 for ; Thu, 27 Jun 2024 10:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719508373; x=1720113173; 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=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; b=VoFIIkGqb09cePHXVDdEjQEUN5m1JXroqmEzO1wUtuffieoMVDejUAqAe4hoNTiBH4 /4OREfsY2qNSLUtwTA9U3Eghxzd51THIgKGeyR9XWE4H6a4C2Lg/p7VlfKtuQ6G3wuvw XsrTfxaHdZajucqpUv8j6FRfln+fA28guT4rVhyUhgEDN84dQlg6f+juCP+UIUrzl+QF VEO5DY19T0pfQ07g+Sfygclz058oAjpQJvoSC7NnHvN05hGC2aTF8v6O5XCpyFiqXPVv HvZYTJQhVI2O5ctYDKu2JXRTXJ7irmRVmm46ejN39gjSijdmTaTJ4dxtc1h7OcFFH9uo SpDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508373; x=1720113173; 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=wa9xIcQNODSrwCgxGYM1DSrbhUURwxNAmEEY/4Qlivk=; b=GWbvi49u+LEnDlxoDoZxLBMQJQBIb+2J60ZsKFjoSxmiLCTIcMmMRh8/mKAOZkRdat LLZux+Pxea8Xp6wG4ZRwFwnsK9yI+YsGo3Afba2QiyG+3cyxh6l2Qz8mKUQTThVYDuSE HqdzKg3t5mLItwq+LrnAQyQivHZO2VykbsmIXgAhhU22G6UWHtK3XmcOh9QXQidzlgRm Rg7i0/SbnZK1mvh4OteqItHJjh76c0zV1egFBuNrdERD5e6CDWKqMVoPt3GyEhj5xovI qIVxCh8Lc0JUMqtPN3zMjYQYOjeyBDPhnsH+DGolF4QVIS9Fr3ud0z/y76Q2tMHBqtHn ybBg== X-Gm-Message-State: AOJu0YzdU63q8weU4FuPmwyCYm7cHOsJrRGvWgJU5MMuVC6sR8+ATK2P V6DFFwa5Aw3qRZtqenVMfPZuO7jyo+FNuatshKSUAPt/2WOvlg7f1+G6r7pNa+ASATQlE9vOCnE Coo0= X-Received: by 2002:ac2:5618:0:b0:52c:dea0:dd55 with SMTP id 2adb3069b0e04-52cdf7f10d2mr9085492e87.24.1719508372617; Thu, 27 Jun 2024 10:12:52 -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-3674357c14fsm2511586f8f.16.2024.06.27.10.12.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 10:12:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Joel Stanley , Luc Michel , Francisco Iglesias , qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Vincent Palatin , Sai Pavan Boddu , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 10/19] hw/sd/sdcard: Implement eMMC sleep state (CMD5) Date: Thu, 27 Jun 2024 19:10:50 +0200 Message-ID: <20240627171059.84349-11-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 Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=philmd@linaro.org; helo=mail-lf1-x134.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é --- 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},