From patchwork Fri Jun 28 07:01:48 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: 808208 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp224693wrr; Fri, 28 Jun 2024 00:13:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWz2YSgSsm7x8DMurU9Pv8v4QhIIOdAHs0WyJAuBzP5IVd9oI4yMBJ9ZYuDXS/FIwZOTm5nd0e5uJC1TsAe8Pzn X-Google-Smtp-Source: AGHT+IF/syvXm1oR/e+nZpTJDQAM+xDJakRi6ClrF+ABT6UxL0W2OE8u94+20p/OH2lCVLbXGvZS X-Received: by 2002:a05:620a:240f:b0:795:5115:5ae3 with SMTP id af79cd13be357-79be47b7035mr1816002885a.50.1719558783627; Fri, 28 Jun 2024 00:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719558783; cv=none; d=google.com; s=arc-20160816; b=CQnrmrExGLkgr+fXaWl3/8rOsrXfq2eKIDJEDjAR21WbrSQ4n6uxKiux20y0ht4ypr 0XJtC+o8AV092twfuPemZHToulRlVd3bei/G+5pefUTFeMc9FDVN9N0Kzd2tOGWmbt+H nCPt9Vr5DwfxnyCvM48hyTH9mtiApylDv/OmBfMoOogAZw6fr3BIiLgD/Fvph8Qjniuz Hv/rK9nlelMfrOGtijtyuKKkGMAeGZh24CKLV6Q/framTmtYN7fYrUK5tUZy3L2tSgzq jg3vRMH48ieclpHic1f3zcj0zmvsrNY8qolodjM38gW3FSANuqwd3Bs7iMcpdTX2F10+ Vsng== 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=bYEYJ2Wwx71dNKsAcy31SFsnrP/uSxrEAbuXlnudJVY=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=kSKdatmLreZAZsAlz3BzEulbyLFf3hQooPAlcKAhJEA9wYFx85RP7PPXKudabJDZv8 s3cfKtci3a468jNcQkzXLSYgc8l08BETAwIoIT+6M/hEGWEIPPHFPzQ/BKGtH54v3578 /UG6uVNmhIFW/bpDLG3k9HB4lC0UP3FLfqOK/tfvxt5qjBlW7cCNZYx6H7gQ4JJEeEOX clCk/UWyIB4JW8m/9Lq1APUNWhcIUjWE1Ug9qUChAKO2R9veAPQdSLshqtMNrDPzsJ8W NK6EPHQ6Jc8TweUdy10nx85g2d+96EdrWz5Hhsqnn9eBkygXLzaY/agYjE90BRv3BIP7 DVoA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b6fK9nKJ; 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-446513c2066si12935851cf.110.2024.06.28.00.13.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:13:03 -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=b6fK9nKJ; 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 1sN5jr-000707-Mh; Fri, 28 Jun 2024 03:09:43 -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 1sN5jg-0006gJ-UE for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:09:36 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5jf-0004W5-7a for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:09:32 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-36743abace4so850647f8f.1 for ; Fri, 28 Jun 2024 00:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558568; x=1720163368; 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=bYEYJ2Wwx71dNKsAcy31SFsnrP/uSxrEAbuXlnudJVY=; b=b6fK9nKJAQuVa+5JRMI1sbIDNE0oZhKdSvfg/Xoz5CYCE00lKzV3UdAuR1bYppHhEa LX3aUVYLGuCca4tW3zqm4dlcqFR2QCKe4N0MJNHn5hhvjmnHg3C70hmM9yvULpbS3gQb NeBgelRDroMS3+7ZF65jgiQmw2sFKSc494SBKkrfZl8NxnXxZQt8PhCyp+3Y1JvF+uzE ZeCkET7qiVbH6rJ5owrYpNnLUIlf6ZJsGUOXA3RQ96Pn16PHPkZjJ6hetbPuPfiiHyLl WM2s1yFRaQucpoPyltiLRixDH06WgGcxbx+7SY+dsCtgnhIGSn3Bk/4k37mytuj98Ywh yY5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558568; x=1720163368; 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=bYEYJ2Wwx71dNKsAcy31SFsnrP/uSxrEAbuXlnudJVY=; b=THKkoFtT4htcpkWSTG/tNLxwjnXZUid/oFjnxvHbeYRh3pHHqb+puIA2qL9UWj1ivt 6vhkMokz+8Czc4akEZnHjZ+oVPCFLM3n49GaYnplwtfxFVL8QXp5Yox/BlZU3sacxHMd 11RIuT8/8nljJS+66LOECAgH16+/DIrc0poAov0D4/LJEBGsFZQ8NJlRjNBNsBx0eun1 YCni50UEBbTcDyo9mwe7iOOh6pEb2vfN+qRHh5rqDJNvpgFhr/yDbpPIFRC8AEsSGQPQ 93gHVd14buORNe73T0Uz1Xw0MOtKJOi4jwhTF3i3a9/C4leiPhy1CfP0FXvQDpd632/z VhDA== X-Gm-Message-State: AOJu0Yx7ak8qd69Zra0cGaBNa1NpgAHHtvyvv6ygDIYF9yhPwx+ZlmHW Zo2vhzufKRu7XfEae6kh3U0LRVtzDEodpwO+bofQ7iZvxSGKThgYpLgQUV4o9vx+EMn1RJauBD5 7EGk= X-Received: by 2002:a5d:64ea:0:b0:366:ea4a:17ec with SMTP id ffacd0b85a97d-3676096eb0emr802635f8f.2.1719558568647; Fri, 28 Jun 2024 00:09:28 -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 5b1f17b1804b1-4256b0c19eesm21379325e9.45.2024.06.28.00.09.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:09:28 -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 72/98] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) Date: Fri, 28 Jun 2024 09:01:48 +0200 Message-ID: <20240628070216.92609-73-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::429; envelope-from=philmd@linaro.org; helo=mail-wr1-x429.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 Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cd207a3090..167e1c517a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1704,6 +1704,50 @@ static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req) return sd_r1; } +/* ACMD41 */ +static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req) +{ + if (sd->state != sd_idle_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + /* + * If it's the first ACMD41 since reset, we need to decide + * whether to power up. If this is not an enquiry ACMD41, + * we immediately report power on and proceed below to the + * ready state, but if it is, we set a timer to model a + * delay for power up. This works around a bug in EDK2 + * UEFI, which sends an initial enquiry ACMD41, but + * assumes that the card is in ready state as soon as it + * sees the power up bit set. + */ + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { + if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { + timer_del(sd->ocr_power_timer); + sd_ocr_powerup(sd); + } else { + trace_sdcard_inquiry_cmd41(); + if (!timer_pending(sd->ocr_power_timer)) { + timer_mod_ns(sd->ocr_power_timer, + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + OCR_POWER_DELAY_NS)); + } + } + } + + if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { + /* + * We accept any voltage. 10000 V is nothing. + * + * Once we're powered up, we advance straight to ready state + * unless it's an enquiry ACMD41 (bits 23:0 == 0). + */ + sd->state = sd_ready_state; + } + + return sd_r3; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1812,43 +1856,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 41: /* ACMD41: SD_APP_OP_COND */ - if (sd->state != sd_idle_state) { - break; - } - /* If it's the first ACMD41 since reset, we need to decide - * whether to power up. If this is not an enquiry ACMD41, - * we immediately report power on and proceed below to the - * ready state, but if it is, we set a timer to model a - * delay for power up. This works around a bug in EDK2 - * UEFI, which sends an initial enquiry ACMD41, but - * assumes that the card is in ready state as soon as it - * sees the power up bit set. */ - if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { - if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { - timer_del(sd->ocr_power_timer); - sd_ocr_powerup(sd); - } else { - trace_sdcard_inquiry_cmd41(); - if (!timer_pending(sd->ocr_power_timer)) { - timer_mod_ns(sd->ocr_power_timer, - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - + OCR_POWER_DELAY_NS)); - } - } - } - - if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { - /* We accept any voltage. 10000 V is nothing. - * - * Once we're powered up, we advance straight to ready state - * unless it's an enquiry ACMD41 (bits 23:0 == 0). - */ - sd->state = sd_ready_state; - } - - return sd_r3; - case 42: /* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) { case sd_transfer_state: @@ -2379,6 +2386,7 @@ static const SDProto sd_proto_sd = { [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, + [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, }, };