From patchwork Thu Jun 27 16:43:41 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: 807875 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp900664wrn; Thu, 27 Jun 2024 09:49:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKmom/zbW236uZuOxEh9ouK6mIufPXYuzKd/Zernvz7aa03M5B3SI2ziW6daNoYJCsAiLKMJMIS8xXX0tpJ8Se X-Google-Smtp-Source: AGHT+IF4vR1t23mBbS9F49uruzPFKVCNnqn1ztOiKMlnNwrEhXrOPAk6a9Rkruby6w7MlM87rzMb X-Received: by 2002:a05:620a:3951:b0:797:e7dd:96f with SMTP id af79cd13be357-79be0d7c79fmr1831030985a.57.1719506942281; Thu, 27 Jun 2024 09:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506942; cv=none; d=google.com; s=arc-20160816; b=qW6M8dAGU0j7kjEtiRAuaq9E9/Oty/Jgl7awi6BPlSPBR83eGfmVKCO3BVc/L1Z03E AS9m7gdVdOMMPaBFU+V40Lt+01WhTGOHt5dQY/V9xoKmkROW3O3oaD6QszOSlEs3LYtE 05gAdnHIMzF03mTdtEzz08pc9fiukX8TVkY4rrweW4JbyXzhNq8iZLAAZNbaE0HWxMTt ORvwswMSMsc/XPOiVeWZqnmol6WaiSgBvh0QSOBrBILY6aRychMkI59cNXgTzEawK5RE pHNvxel6LVYpS0QfyWRmdNUW8YLrBkljIDwDbu5uabAXxQ4aHYXt5qk1Wpn4Tz6HeaE/ JUZA== 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=jmktXx8YFnfnnA13QTx+BBHRiUUuhl67+QJQQVhLdE0=; fh=v4x9Oqm5dSIIGNwhX3iTRsusFrFNP2dDaR6uZLPgHBY=; b=lyDqBEo5I4iRG7V1N/e0P3VfQ/MVg9geraChC6Sjmf5Ihzd7cjy/VgVucND0yo6ENJ BVq3YXQOGdZs8n4RbXJrUDRLX0XImS5iiElCJkX4QTVbOjxPLZE0xCxUy2vDhZuxR8ov sHSI2Wx/d4Gh1v+wG3ar6Pi8vP/T0ryVZkWp7O9yOwxCmicOO8WBL8LksVHwLe6F3Ut/ 33Z5cIHqYCqYTdjNOTJ9vvAk49I9CvSqG/5RkmTRot8zTXRQcINguBpFxKPxqQbiAfso ErhndrMvYjoyp6QttvWB/gOjOyOKfVd5uG8XBtMU4ui/Od2qaTbNC8YMZOPZzM8CencG UkLQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F7BB2z5Y; 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-79d5c8c4070si163832885a.551.2024.06.27.09.49.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:49: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=F7BB2z5Y; 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 1sMsHw-0007Sw-TH; Thu, 27 Jun 2024 12:48:00 -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 1sMsGp-0006V5-Kc for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:46:54 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMsGn-0000UV-Vz for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:46:51 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42138eadf64so69478395e9.3 for ; Thu, 27 Jun 2024 09:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506807; x=1720111607; 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=jmktXx8YFnfnnA13QTx+BBHRiUUuhl67+QJQQVhLdE0=; b=F7BB2z5YkaS/+odxUjra9tzOgYOrIV6Ou/kh2OnWNPnCRywOK/hTF6KX+ox+IJcswQ fyCmtR1snKfwf15BkVy7CaRjmKj/rjLR5ldNKTzYz0TLsy/6nzkQrveXH/L7011r5Xzj fYOah0IU1Ybem8DymsWLihsgD6dVfEuB55oyYdhbVWOHyH8461wp5VJWHcdr4WXfpj1J hPMNiRiHvEmsYlB8OtsTS+PtIUhuOv2e+jLR3DRkwO6xfhyJFYFg72j5DUsu8slYtHMD hXUY8v0z2+6VLwpRjF32Dx0BSCLjqfK9lbOCZMB8/mot/ImEwvz/CuusfPws5OFhwC2u ZefQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506807; x=1720111607; 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=jmktXx8YFnfnnA13QTx+BBHRiUUuhl67+QJQQVhLdE0=; b=Xh+RBfEMjjXzFQnlDKQVMcy2HcgROkqCay7IfeZ7j15So1H5e3fUuStwUIOGKXKTlW XFYVc8phgFT+tu65/D4oJ2P3pW2FFsX1hiwgBHq9rdhvVnJ8wdJWteBKhmFbNV9Vam1g NXwmjvxV2PVi502kXiFkZiL8sCFSkZWURyHpoM+edDywE3yvuv5mQsy1DEDh24wdoTHR VO1QQbk/zXWnITmFr65MQG66ElU9lQwDRzKIIcpLCApmYJzIV5fQTjJ8CNxCJo3Vl1FG 795FST/u2O/l6l2LpXYnX6rFwjG3/bkalLuWuPAASHh0ljmfUexRYB7FJS2Yg26fEPd2 2bcg== X-Gm-Message-State: AOJu0YxpYUZ/YHFD1NJJP9q0l3xHD2ScTZpDVZObXrCBNuNqGeyv0oth fgx8u1wH7pQZS9fGlAMOI1I0OVewByPOT4XLB7P1s5rRVaJeEng/ohKFqtzUwSrQpygZ4lkQpsV fan8= X-Received: by 2002:a05:600c:458d:b0:424:781a:188b with SMTP id 5b1f17b1804b1-4248cc58a63mr105770785e9.31.1719506807564; Thu, 27 Jun 2024 09:46:47 -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 5b1f17b1804b1-4256798ce18sm22530645e9.23.2024.06.27.09.46.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:46:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Sai Pavan Boddu , Francisco Iglesias , Joel Stanley , Luc Michel , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH 18/21] hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55) Date: Thu, 27 Jun 2024 18:43:41 +0200 Message-ID: <20240627164345.82192-19-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627164345.82192-1-philmd@linaro.org> References: <20240627164345.82192-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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 Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4d78ac5b59..5461e56e17 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", @@ -1624,9 +1623,34 @@ static sd_rsp_type_t sd_cmd_LOCK_UNLOCK(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, 0); } +/* CMD55 */ +static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_ready_state: + case sd_identification_state: + case sd_inactive_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) { + qemu_log_mask(LOG_GUEST_ERROR, + "SD: illegal RCA 0x%04x for APP_CMD\n", req.cmd); + } + /* fall-through */ + default: + break; + } + if (!sd_is_spi(sd) && !sd_req_rca_same(sd, req)) { + return sd_r0; + } + sd->expecting_acmd = true; + sd->card_status |= APP_CMD; + + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { - uint16_t rca; uint64_t addr; sd->last_cmd_name = sd_cmd_name(sd, req.cmd); @@ -1713,29 +1737,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); /* Application specific commands (Class 8) */ - case 55: /* CMD55: APP_CMD */ - rca = sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_ready_state: - case sd_identification_state: - return sd_illegal; - case sd_idle_state: - if (rca) { - qemu_log_mask(LOG_GUEST_ERROR, - "SD: illegal RCA 0x%04x for APP_CMD\n", req.cmd); - } - default: - break; - } - if (!sd_is_spi(sd)) { - if (sd->rca != rca) { - return sd_r0; - } - } - sd->expecting_acmd = true; - sd->card_status |= APP_CMD; - return sd_r1; - case 56: /* CMD56: GEN_CMD */ switch (sd->state) { case sd_transfer_state: @@ -2321,6 +2322,7 @@ static const SDProto sd_proto_spi = { [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, }, .acmd = { @@ -2373,6 +2375,7 @@ static const SDProto sd_proto_sd = { [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional},