From nobody Tue Feb 10 16:44:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.45 as permitted sender) client-ip=209.85.221.45; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f45.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544548; cv=none; d=zohomail.com; s=zohoarc; b=J0LAxpndF4/sgFfiz3FNXpFX7vWZ4wrAQplM6g9dq4DlHNoZ3x86QchqIH2W4prk7ITApDcmKLDYaAbv+GT/gJkjcZC0Cu3g7OFgUWiD1v41DxzSs7gfd227+loWO9w0ypbt3iIx9eAqlLfb6KvA2TrU0gxzlABkq4yqQrDqcR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544548; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WBraHyjmGr6XeI21kbbyD3nKLW6L5v9q4ad+mz4xwSY=; b=Do3Y5HKKcCjQ3LTEamvqrZvpfJn0ZcGFg7V/XJb7/m3Hwi6W1W7SiHndMSCbpxUtUoeGtuT3/uBpb0X7YlcR03ZLpI7f9hEJUeVYlgY4haJfdRJHURt7TOHh1cvI2eal9mtcg/I61wTNHVrQre63YVdd8tWM7K9ik5goIkH/zCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by mx.zohomail.com with SMTPS id 1624544548788329.1772539237031; Thu, 24 Jun 2021 07:22:28 -0700 (PDT) Received: by mail-wr1-f45.google.com with SMTP id h11so6876163wrx.5 for ; Thu, 24 Jun 2021 07:22:27 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id e11sm3290531wrs.64.2021.06.24.07.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WBraHyjmGr6XeI21kbbyD3nKLW6L5v9q4ad+mz4xwSY=; b=eGZRapmrGlXpGUcDzSRBfIice1Nc5ySOwuBv57ra2GK+BvtDeqS2h9Gl63CzV8qEnj q95fFB4RdM3XkC1yWKTe2wWMwqPaPWQpCqZt3cLhO3B4Y3cxGohl6OEVe7Q9+RsyyTpA upg8tKe2VH0aRX43j2ebhM92/A+kRPK7Gc2/2YxNk/WkGG9zn8eEiJeuU89CH2p4ZhdH Q6xvYVa9Hyejr0ehhCnDyaZDlAi06yWS7EQpWtjDO0HmS+V6COQPbdM/A4VBrQWGJltK cxptBfSXx1w+jaEKtWR60T14ovpmztEqqXxpySJS/A+EFw7PBxman12Q9dvOXKjgI79q 4dJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WBraHyjmGr6XeI21kbbyD3nKLW6L5v9q4ad+mz4xwSY=; b=X0hwtuuvvoR+ZJGD6w8Tdx2MhEkXShtNKZR0azd7/bqn3TSUv5zalsRFbW8+SEdR8g c4c3+Zykv7trFYaA+mKpZh+wuJTQML3uv76AyZHK5jTz2CZtR83dm5sUsJhZZj/50XpC QloDm8/YShYMGYy4K4kPMjwMZMqD9EvGQ0bzywVqBQtGziF56kc8CV+WT+rtrH9vY91b L1oncCC3n9cmGOleFFECmnhxgzeTBnWRJidPdQTc+kEuVSobYDjZ28q8p33VCysocyM0 wLokf3iRGPiFE3JDMjXSiwu7kQLyyeIT35IeTGK5HXi3MaBFwR9n2Ut3cuel/Bpd5TxI +r8Q== X-Gm-Message-State: AOAM530uTe2or7Yqb1bc3jkLAQ9nOMUwnVq45ZjhFvALC4NaYszNgHg+ wm0mvMVxjS+ODG/kcJ7HzM8= X-Google-Smtp-Source: ABdhPJzJ7UKKUcLkV8WV49CIiVgT+x9EwHSyNCzlgpXJbQUol1x2SmtOy63OReqWBLq1tepAM632+A== X-Received: by 2002:a5d:6d8b:: with SMTP id l11mr4789719wrs.21.1624544545943; Thu, 24 Jun 2021 07:22:25 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Andrew Jeffery , Bin Meng , Joel Stanley , qemu-block@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH 03/10] hw/sd: Move proto_name to SDProto structure Date: Thu, 24 Jun 2021 16:22:02 +0200 Message-Id: <20210624142209.1193073-4-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624142209.1193073-1-f4bug@amsat.org> References: <20210624142209.1193073-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Introduce a new structure to hold the bus protocol specific fields: SDProto. The first field is the protocol name. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d71ec81c22a..a1cc8ab0be8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -88,6 +88,10 @@ enum SDCardStates { sd_disconnect_state, }; =20 +typedef struct SDProto { + const char *name; +} SDProto; + struct SDState { DeviceState parent_obj; =20 @@ -112,6 +116,7 @@ struct SDState { =20 /* Runtime changeables */ =20 + const SDProto *proto; /* Bus protocol */ uint32_t mode; /* current card mode, one of SDCardModes */ int32_t state; /* current card state, one of SDCardStates */ uint32_t vhs; @@ -138,7 +143,6 @@ struct SDState { qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; - const char *proto_name; bool enable; uint8_t dat_lines; bool cmd_line; @@ -951,8 +955,8 @@ static bool address_in_range(SDState *sd, const char *d= esc, =20 static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) { - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state: %s\n", - req.cmd, sd_state_name(sd->state)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong state: %s\n", + sd->proto->name, req.cmd, sd_state_name(sd->state)); =20 return sd_illegal; } @@ -966,7 +970,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDR= equest req) * However there is no ACMD55, so we want to trace this particular cas= e. */ if (req.cmd !=3D 55 || sd->expecting_acmd) { - trace_sdcard_normal_command(sd->proto_name, + trace_sdcard_normal_command(sd->proto->name, sd_cmd_name(req.cmd), req.cmd, req.arg, sd_state_name(sd->state)); } @@ -1526,7 +1530,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { - trace_sdcard_app_command(sd->proto_name, sd_acmd_name(req.cmd), + trace_sdcard_app_command(sd->proto->name, sd_acmd_name(req.cmd), req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |=3D APP_CMD; switch (req.cmd) { @@ -1820,7 +1824,7 @@ void sd_write_byte(SDState *sd, uint8_t value) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return; =20 - trace_sdcard_write_data(sd->proto_name, + trace_sdcard_write_data(sd->proto->name, sd_acmd_name(sd->current_cmd), sd->current_cmd, value); switch (sd->current_cmd) { @@ -1976,7 +1980,7 @@ uint8_t sd_read_byte(SDState *sd) =20 io_len =3D (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; =20 - trace_sdcard_read_data(sd->proto_name, + trace_sdcard_read_data(sd->proto->name, sd_acmd_name(sd->current_cmd), sd->current_cmd, io_len); switch (sd->current_cmd) { @@ -2095,6 +2099,14 @@ void sd_enable(SDState *sd, bool enable) sd->enable =3D enable; } =20 +static const SDProto sd_proto_spi =3D { + .name =3D "SPI", +}; + +static const SDProto sd_proto_sd =3D { + .name =3D "SD", +}; + static void sd_instance_init(Object *obj) { SDState *sd =3D SD_CARD(obj); @@ -2115,7 +2127,7 @@ static void sd_realize(DeviceState *dev, Error **errp) SDState *sd =3D SD_CARD(dev); int ret; =20 - sd->proto_name =3D sd->spi ? "SPI" : "SD"; + sd->proto =3D sd->spi ? &sd_proto_spi : &sd_proto_sd; =20 switch (sd->spec_version) { case SD_PHY_SPECv1_10_VERS --=20 2.31.1