From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B874C2B9F4 for ; Mon, 28 Jun 2021 07:31:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0FE95619C4 for ; Mon, 28 Jun 2021 07:31:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FE95619C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lxljW-0000qt-2b for qemu-devel@archiver.kernel.org; Mon, 28 Jun 2021 03:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lxlhp-0007om-Ft for qemu-devel@nongnu.org; Mon, 28 Jun 2021 03:29:21 -0400 Received: from 8.mo52.mail-out.ovh.net ([46.105.37.156]:48168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lxlhn-0001S9-Iz for qemu-devel@nongnu.org; Mon, 28 Jun 2021 03:29:21 -0400 Received: from mxplan5.mail.ovh.net (unknown [10.109.156.98]) by mo52.mail-out.ovh.net (Postfix) with ESMTPS id 771CA284497; Mon, 28 Jun 2021 09:29:15 +0200 (CEST) Received: from kaod.org (37.59.142.95) by DAG4EX1.mxp5.local (172.16.2.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10; Mon, 28 Jun 2021 09:29:14 +0200 Authentication-Results: garm.ovh; auth=pass (GARM-95G0010458d80a-5846-4bfc-b720-e92b5ee72d2f, A5942444232ACF3D755B1638A42E9F49C81D83AA) smtp.auth=clg@kaod.org X-OVh-ClientIp: 82.64.250.170 Subject: Re: [RFC PATCH 04/10] hw/sd: Introduce sd_cmd_handler type To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , References: <20210624142209.1193073-1-f4bug@amsat.org> <20210624142209.1193073-5-f4bug@amsat.org> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= Message-ID: <76d91bb6-c8ac-6d33-a5f1-9f196ea54756@kaod.org> Date: Mon, 28 Jun 2021 09:29:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210624142209.1193073-5-f4bug@amsat.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [37.59.142.95] X-ClientProxiedBy: DAG7EX1.mxp5.local (172.16.2.61) To DAG4EX1.mxp5.local (172.16.2.31) X-Ovh-Tracer-GUID: 1166d9d9-d540-4666-840b-40ed7d8b971f X-Ovh-Tracer-Id: 8812137097908161318 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrfeehfedguddufecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefuvfhfhffkffgfgggjtgfgihesthekredttdefjeenucfhrhhomhepveorughrihgtpgfnvggpifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucggtffrrghtthgvrhhnpeejkeduueduveelgeduueegkeelffevledujeetffeivdelvdfgkeeufeduheehfeenucfkpheptddrtddrtddrtddpfeejrdehledrudegvddrleehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepmhigphhlrghnhedrmhgrihhlrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpegtlhhgsehkrghougdrohhrghdprhgtphhtthhopehfgegsuhhgsegrmhhsrghtrdhorhhg Received-SPF: pass client-ip=46.105.37.156; envelope-from=clg@kaod.org; helo=8.mo52.mail-out.ovh.net X-Spam_score_int: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-1.765, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , Bin Meng , Joel Stanley , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 6/24/21 4:22 PM, Philippe Mathieu-Daudé wrote: > Add 2 command handler arrays in SDProto, for CMD and ACMD. > Have sd_normal_command() / sd_app_command() use these arrays: > if an command handler is registered, call it, otherwise fall > back to current code base. > > Signed-off-by: Philippe Mathieu-Daudé > --- > hw/sd/sd.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/hw/sd/sd.c b/hw/sd/sd.c > index a1cc8ab0be8..ce1eec0374f 100644 > --- a/hw/sd/sd.c > +++ b/hw/sd/sd.c > @@ -88,8 +88,12 @@ enum SDCardStates { > sd_disconnect_state, > }; > > +typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); > + > typedef struct SDProto { > const char *name; > + sd_cmd_handler cmd[SDMMC_CMD_MAX]; > + sd_cmd_handler acmd[SDMMC_CMD_MAX]; > } SDProto; A class would be better but it's no big deal for the moment. > > struct SDState { > @@ -994,6 +998,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) > return sd_illegal; > } > > + if (sd->proto->cmd[req.cmd]) { > + return sd->proto->cmd[req.cmd](sd, req); > + } > + I expect that some default array will be used to initialize ->cmd ? Thanks, C. > switch (req.cmd) { > /* Basic commands (Class 0 and Class 1) */ > case 0: /* CMD0: GO_IDLE_STATE */ > @@ -1533,6 +1541,11 @@ static sd_rsp_type_t sd_app_command(SDState *sd, > trace_sdcard_app_command(sd->proto->name, sd_acmd_name(req.cmd), > req.cmd, req.arg, sd_state_name(sd->state)); > sd->card_status |= APP_CMD; > + > + if (sd->proto->acmd[req.cmd]) { > + return sd->proto->acmd[req.cmd](sd, req); > + } > + > switch (req.cmd) { > case 6: /* ACMD6: SET_BUS_WIDTH */ > if (sd->spi) { >