From patchwork Fri Jun 28 07:01:16 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: 808190 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp223805wrr; Fri, 28 Jun 2024 00:10:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVvXHumYeqjwX1neeOfoe55Jk2GguePyKfd/ZruHydumTc5T+6XL/QWQa2IwvD5E1mCdl++1tCxB25NDblfm2OM X-Google-Smtp-Source: AGHT+IFRUnmMuK5Y6SEpQLsQFoUiedhN3NAT+h47zthG1z2ssClf55IIuJHbgAiVkTcG1VouWxLu X-Received: by 2002:a05:6214:242e:b0:6b5:5687:8f7a with SMTP id 6a1803df08f44-6b5a545b318mr13862086d6.21.1719558605499; Fri, 28 Jun 2024 00:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719558605; cv=none; d=google.com; s=arc-20160816; b=uqQ8cCU3U70U7CMaQXqv/d0LhlbnYZOuiBdClYK+SAM+xCrQqbEnhyYuhgijq5sTcc aruM4LcSj0l99Zw3EnQMxoX0DVvcWbTlOAVO3eKMKBhpHb4Rl5AFszNFruUUx4eobCoL 59TMz6rIzhnDxcJ32FZ+r8miewUjSlX/Ewn1ZB9zTw0/Dk0fetkJ9CXAwlejCVy73OvT jJzYS4Th7x74YRTqv9rRW9QpgaV76LZxjwhL5SMAOo806ozcBrOjb6tM7JhbX2s7Q+kR +fDBw9jfuhz+gnfWfUYGV53fGMS4bmH3M6EUU7KQGJ59NWzK3VtidobBJjLJwZjXkim4 4pCA== 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=FQYmSrnXt5mY866BTgrOijDYx76JFvHs12wH0ygKj7I=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=FcERBfsZSd5wMqz260rLB0fZac3XwZjBUMp24M6hrpk5ZUaj1bTGoWpjhnECCUrbel LOtNgmqh2+JWM73aphBo4ugvqCOD0icC67/byCFBDZvHhA0pGbfu1asPf8N0QFvwqJLB X06DYL5iSeP+k3iPdoG6p2ADDXhmCzWvyAHaC0I/RuzNO1fAK1QtXWEFFJgRZMJjEwBf C6iFxPriZIztpms6zW1MPZJo2bjjaZm/Xg8SPK1Ad2kTQISZ5WribFBcFpAEuXHAf97X 6R/5pUftRZHm7G2FrCQl8YEorzX1VWRpaWD0pJmoiYG4N3ovMcLycbodf0Whl36x+fHX 3+qw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TZxUyhwA; 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-6b59e618646si13702706d6.583.2024.06.28.00.10.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:10:05 -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=TZxUyhwA; 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 1sN5go-0002i7-V0; Fri, 28 Jun 2024 03:06:35 -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 1sN5ga-0002KM-A4 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:06:22 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5gY-0003Fk-Cb for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:06:20 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2ec10324791so2203441fa.1 for ; Fri, 28 Jun 2024 00:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558376; x=1720163176; 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=FQYmSrnXt5mY866BTgrOijDYx76JFvHs12wH0ygKj7I=; b=TZxUyhwATKwfwTVrYupmg4bwOOQyQkP0CjqetVsvXTlAs5RuZzXfMRUjCh2IS1u2eY 2wGPCg5JxZtjgiHnZ7Rh6/OpmtOSyVunb2eEKhJI8lVQYRIxOUEitRaLDrrsVa6Laq7S 5zwk5nAWI8gHE5u1fpWSBOsZgKtagixvKLLhtoVNhKs+Qhe7yZyp4jjUqnZVKl+kKoOt 41S4wIwhHnEsUjQWFPIGj2DPiDRp53XeAndV601sDdXbm+OjooVl5fX9+M+xPxdmTazn Ab8+VGtKGRCePxawpypRejx0x4I9soAUGUZMueVu+mUMv1LxOzvuX5TgW61nsTj5+m8Q 7I5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558376; x=1720163176; 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=FQYmSrnXt5mY866BTgrOijDYx76JFvHs12wH0ygKj7I=; b=GII1PvAYbti2jIKUBHTyo7ab4wStBHGhMd1K8GfuAITX5xBVUmQLOwD2FpPKSL+mRK ib6Wh8oEOUlF/wlEuBZ1V77lnlhpgq0/85cgWLDE6vglFfhmamLlEFhyVOLwkEciryoa k3gdMjB8pCmB7stM03+Ag8nuv2LChwar9r1iHIHaRQ4QsTrFGwI+M2dIUspe2lHZfbVg ENMJAyYOKqf49JzRfeL9erlhIqDxLTmXAEtFFpABXLn6vILVz3gk1oxyqR5eStzk/4L+ i+gWPaoHMm/32/dW88HaEGKM2O0bFuBzxBWVRPix0220zhYyxxArD/x9ZVtq/UEWFMcf 6jNA== X-Gm-Message-State: AOJu0YzNxEsFL4tdXfTd5rDQRMNVz+/hC6vTc2Sm8h6UoNio55CtYUZw tzzBIBtT8cZYvw90Yruqw93qRb9kzpA6vjuaQLQWYyC4l0A0CD5EIfS9xzsiJingrSCQQnd3Iey Rpk0= X-Received: by 2002:a2e:9985:0:b0:2ec:5128:1850 with SMTP id 38308e7fff4ca-2ec5b27e720mr92735051fa.13.1719558375878; Fri, 28 Jun 2024 00:06:15 -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-4256b09a2bcsm21072595e9.36.2024.06.28.00.06.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:06:15 -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 40/98] hw/sd/sdcard: Store command type in SDProto Date: Fri, 28 Jun 2024 09:01:16 +0200 Message-ID: <20240628070216.92609-41-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::234; envelope-from=philmd@linaro.org; helo=mail-lj1-x234.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 Store the command type altogether with the command handler and name. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- include/hw/sd/sd.h | 5 +++-- hw/sd/sd.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 2c8748fb9b..29c76935a0 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -76,8 +76,9 @@ typedef enum { } sd_uhs_mode_t; typedef enum { - sd_none = -1, - sd_bc = 0, /* broadcast -- no response */ + sd_none = 0, + sd_spi, + sd_bc, /* broadcast -- no response */ sd_bcr, /* broadcast with response */ sd_ac, /* addressed -- no data transfer */ sd_adtc, /* addressed with data transfer */ diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 97fb3785ee..c4cc48926d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const sd_cmd_type_t type; const char *name; sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX], acmd[SDMMC_CMD_MAX]; @@ -351,20 +352,6 @@ static void sd_set_mode(SDState *sd) } } -static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] = { - sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, - sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, - /* 16 */ - sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, - sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, - /* 32 */ - sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, - sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, - /* 48 */ - sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, - sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, -}; - static const int sd_cmd_class[SDMMC_CMD_MAX] = { 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, @@ -571,10 +558,19 @@ static void sd_set_rca(SDState *sd, uint16_t value) static uint16_t sd_req_get_rca(SDState *s, SDRequest req) { - if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) { + switch (s->proto->cmd[req.cmd].type) { + case sd_none: + /* Called from legacy code not ported to SDProto array */ + assert(!s->proto->cmd[req.cmd].handler); + /* fall-through */ + case sd_ac: + case sd_adtc: return req.arg >> 16; + case sd_spi: + g_assert_not_reached(); + default: + return 0; } - return 0; } /* Card Status register */ @@ -2277,22 +2273,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { - [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [1] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [0] = { sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, .acmd = { - [41] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [41] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; static const SDProto sd_proto_sd = { .name = "SD", .cmd = { - [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [2] = { "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, - [3] = { "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, - [19] = { "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, - [23] = { "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [0] = { sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [2] = { sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] = { sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [19] = { sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [23] = { sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, };