From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.44 as permitted sender) client-ip=209.85.128.44; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f44.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544538; cv=none; d=zohomail.com; s=zohoarc; b=GEOa4nbxolIccgM3L/6ybyuDlwy3Y2EgMYgminT7ZqUouneDx2kwbnDF/cUN3I1oxK950jTWbVvGTSILHLloI5xNqQN8iKOsPS4el7mj8re3dFvS5DEczLGT7PEwT8/UJpLUPttuGv/v4QnT1+gBsn9M1Z7QtRfpnvmygwS0T3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544538; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CELNymjR/8pwAF7b6jcb3aIuZvp+QTfxg6AbWcEaa2w=; b=bl3iMdeZPyaQyX8k8NusFPQCk/IH+IxKy2+JaOlabQjsO6VGQjdVhNPLablVfBrxZKnxI/V/Grqw3y+OyJTv3H2YQNIL4ublyjs2Kvdz9XYKaSTxLh0Ps86O59FxRudeHDf9Nyp6N1vcUqEmEdrDVGdnjWkZBpjlFxeYoCRMXQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mx.zohomail.com with SMTPS id 16245445382356.045993795878076; Thu, 24 Jun 2021 07:22:18 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id j10so4126141wms.1 for ; Thu, 24 Jun 2021 07:22:17 -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 g7sm16121wmq.27.2021.06.24.07.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:16 -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=CELNymjR/8pwAF7b6jcb3aIuZvp+QTfxg6AbWcEaa2w=; b=XNP2q+upJXB8OfRl7+3GITQyL9vqcNFZWNeZbdt1/m3VbIN/h+f6OCOmyvRsX3KhJP 2Y12RVAwaxGcgWcp75lU7/W0AoMybDp5LKldsxQobDHh6uPqdwKCmMYEZ30IXkXQdpmD cnCbuXOKkVue8EABxbA4QnN0ffjXmBPjPPVq0BnFV3Su6e66sapO6VG1sDgynrNzZRDJ /SISFeWCfk+N0Pg0vhVZ9XS6xxOoLnMkhOzqNlXO8IamzyQOqEO4JO89qyyNPqThSB0O 3ge7EHmTHs9ToajywVOIHqMhUdT2sG4Ird1ClaQcqMEy7QECs7R7aFJ5P1ZHJRfhKWMd scbg== 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=CELNymjR/8pwAF7b6jcb3aIuZvp+QTfxg6AbWcEaa2w=; b=CCRccLe/nKsjWsQoabLilpXjXLPomovHoNx+Ihsp4AJa9zum8tLF7M2Rkll/4pbtlh O2SfgXBZ7O3UPhq4c1IOxgG4k2a80HJfJZ63RtkYGbf/78wbDRkf//nutgT75FH/k8Js YL+pBJgk9uftxvLBHmuX6etEHrEaebWt/6uRTzwo9irbswv+RegX1Qe0QbODNnR1gx47 DkuvqakLSpq9/jJn4eOOMPd7Ztx/lbvkqzF+XPsNnSWBH+u5WAvACjlYfZNbICF29f0/ 5nagw3yTnZFDZDlwmMcwUGs7DW3NvutcGrfr/ri/+44IUN/ZZnr2JH75GrCbVBHwseQn mqOA== X-Gm-Message-State: AOAM533AqKZevuNROm2wUmoGgGOnap18iKMb8YijHq3CCaUGF/iG+3o0 2/C+ehxp33rXxtfzbk38sDk= X-Google-Smtp-Source: ABdhPJwyA+pGRoln1P3Q55Z3GpfdFXAoG5WclsqFpS74C8uFmjAP5OR+upxhxL97vV5TyaMhfeYdZw== X-Received: by 2002:a05:600c:c6:: with SMTP id u6mr4593816wmm.146.1624544536469; Thu, 24 Jun 2021 07:22:16 -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 01/10] hw/sd: When card is in wrong state, log which state it is Date: Thu, 24 Jun 2021 16:22:00 +0200 Message-Id: <20210624142209.1193073-2-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) We report the card is in an inconsistent state, but don't precise in which state it is. Add this information, as it is useful when debugging problems. Since we will reuse this code, extract as sd_invalid_state_for_cmd() helper. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 282d39a7042..288ae059e3d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -937,6 +937,14 @@ static void sd_lock_command(SDState *sd) sd->card_status &=3D ~CARD_IS_LOCKED; } =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)); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1504,8 +1512,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) return sd_illegal; } =20 - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state\n", req.cmd= ); - return sd_illegal; + return sd_invalid_state_for_cmd(sd, req); } =20 static sd_rsp_type_t sd_app_command(SDState *sd, --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) client-ip=209.85.128.42; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f42.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544542; cv=none; d=zohomail.com; s=zohoarc; b=nDv7BnpmEqMg5d3I030VIhJaDg+bnE1NJtXudXC/f2oblTZq8Kdsj2DKR1S5OMMdSkL3ri4bBq/tiNCq2kd+TChKT2jWyGJezQn3LGQAaopcZpqaKeoLH9CQkUUfAuOW2YUXA4T5lKG/KReDLDQE449EQpXeEntEzsFvD3WElgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544542; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yzWkWf0NgppWHdk+Kcq3Byckt7guuXJzjXQjHJnxzrw=; b=mYR18SHeN0+26txYTYRtT0GkWJgILcncWdO3IseYhfzsQ4jmirhoG7Zj4VSxloHcopY96AhsIFvurKVlfn6ZJckl58ddvOhdSYwGar1g/rmjQRJZhvSb0asFbE78J54SA7Shut4MjI3geIlN3xRx8uCBB/mOIpQUlNGCJtccFMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mx.zohomail.com with SMTPS id 162454454290396.92626828090602; Thu, 24 Jun 2021 07:22:22 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id h21-20020a1ccc150000b02901d4d33c5ca0so3754098wmb.3 for ; Thu, 24 Jun 2021 07:22:22 -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 k6sm3051919wms.8.2021.06.24.07.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:20 -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=yzWkWf0NgppWHdk+Kcq3Byckt7guuXJzjXQjHJnxzrw=; b=VkVbepToYtfuoggzQfIqBvRAofLtNswHJE5f0nSAD0JOCgLjzIkmQ/yaydHVWt6T9G a9Izja+1JDdgF1rdL7jVP8g0Dq6IFfOjVVhPVv1gxv1onKOHKbhefJ4o6+3fbDT6zcbz TXqLewhHJkeG8JCMiRJHFgjd4RklrEdF6CHAKwMp4Owq7lRKVXt9yV3GuQk5k0MEs+Gu BCK1UpzCh4xrH5pyyb/rJOSAx8OOLy2IjuEz9VnkL8jfUQTELR1lfhUC+0yyahIz2V84 NAcT5VcqDUVGIhotj6o7c4blpAcQnhkcwKfoTgCAXFfn2pV7yIFbvXOXCdUHEaoXUX08 vubg== 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=yzWkWf0NgppWHdk+Kcq3Byckt7guuXJzjXQjHJnxzrw=; b=a20u65Yv7dGj4nJMR3O5rLJ16veAqG0L8W2BAayZ961+27NpbAqPRjVHapuIAGWRx0 vwgmN8dtzEU76huinOanjEQpLttY63o1qNQRnPs2nEvFrIsNocIgKhPhcse/lTRPjRAx 7YYNcP5YxPHBJVI0Yd0aySEfGfNldWikvUZk0uj23BTAHG98uIeEeC8BaGEs6Hkjv8qI CDp/+uxosnHcU+BApFAAn4KLZuCjE08jR+/4JawOswrrKHprf6JCqjCvk+DymOdkQoVE 7M8KxOCw38cb/94zgNdNb7KDd6EX2bhwUlf6Kscjnesm/7p1K5PmDMEcU6wcVIP3XdW2 zTQA== X-Gm-Message-State: AOAM533Ic8Cvi3wfbCUVbCpAB8731xnJQFGTN+uKENf3tve4RNXfxh3N XTls1evX6HMPPPwCbviycPI= X-Google-Smtp-Source: ABdhPJxI2gZhVXutL5R1WUFC4oiBazKhYOvmZobtprwoMbANFz9X4Z+BXJ0HfpEGZNjfiubB80ZWVw== X-Received: by 2002:a05:600c:19d1:: with SMTP id u17mr4721338wmq.31.1624544541185; Thu, 24 Jun 2021 07:22:21 -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 02/10] hw/sd: Extract address_in_range() helper, log invalid accesses Date: Thu, 24 Jun 2021 16:22:01 +0200 Message-Id: <20210624142209.1193073-3-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) Multiple commands have to check the address requested is valid. Extract this code pattern as a new address_in_range() helper, and log invalid accesses as guest errors. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 288ae059e3d..d71ec81c22a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -937,6 +937,18 @@ static void sd_lock_command(SDState *sd) sd->card_status &=3D ~CARD_IS_LOCKED; } =20 +static bool address_in_range(SDState *sd, const char *desc, + uint64_t addr, uint32_t length) +{ + if (addr + length > sd->size) { + qemu_log_mask(LOG_GUEST_ERROR, "%s offset %lu > card %lu [%%%u]\n", + desc, addr, sd->size, length); + sd->card_status |=3D ADDRESS_ERROR; + return false; + } + return true; +} + 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", @@ -1226,8 +1238,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) switch (sd->state) { case sd_transfer_state: =20 - if (addr + sd->blk_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "READ_BLOCK", addr, sd->blk_len)) { return sd_r1; } =20 @@ -1272,8 +1283,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) switch (sd->state) { case sd_transfer_state: =20 - if (addr + sd->blk_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "WRITE_BLOCK", addr, sd->blk_len)) { return sd_r1; } =20 @@ -1333,8 +1343,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) =20 switch (sd->state) { case sd_transfer_state: - if (addr >=3D sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "SET_WRITE_PROT", addr, 1)) { return sd_r1b; } =20 @@ -1356,8 +1365,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) =20 switch (sd->state) { case sd_transfer_state: - if (addr >=3D sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "CLR_WRITE_PROT", addr, 1)) { return sd_r1b; } =20 @@ -1832,8 +1840,8 @@ void sd_write_byte(SDState *sd, uint8_t value) case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ if (sd->data_offset =3D=3D 0) { /* Start of the block - let's check the address is valid */ - if (sd->data_start + sd->blk_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "WRITE_MULTIPLE_BLOCK", + sd->data_start, sd->blk_len)) { break; } if (sd->size <=3D SDSC_MAX_CAPACITY) { @@ -2005,8 +2013,8 @@ uint8_t sd_read_byte(SDState *sd) =20 case 18: /* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset =3D=3D 0) { - if (sd->data_start + io_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; + if (!address_in_range(sd, "READ_MULTIPLE_BLOCK", + sd->data_start, io_len)) { return 0x00; } BLK_READ_BLOCK(sd->data_start, io_len); --=20 2.31.1 From nobody Mon Feb 9 15:58:29 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 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) client-ip=209.85.221.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544554; cv=none; d=zohomail.com; s=zohoarc; b=gEjLhuEVfxF8SwLbAIn4hILTducF/R9FBz5jdJPliY6xMuVyDL8gVGbdXKenUIzyewsfKhpCvwPheW2fR4e8r0pSEx+Itd1UScqkw4HR/qtEC0CeF5icRoUdPZCMlSRNHM2rSb/GWjtlLloisoh+nhkoJQ8vrzWjvR2TSV++neE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544554; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XdJG7ZIE4+jGMuoiadGQKywOCCIK+dcTPMT2LT+HY3I=; b=ZJ6RQIXQZDu9dG/gvEHQlTr8TcJWzOAxVXIeiv9zOYD+yFF8f85BizTDXjYdJdIw2uoDCDN0vFt+CZNjpt35B4PbXmRiC1T47FoYzEEfAdkuvQr07A4ZgfuJjUt4xrfThcE4FaE3opijtRlcwkUrheGVUX4g1ijyk5I9bQe4tLs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.zohomail.com with SMTPS id 1624544554862510.1243561472302; Thu, 24 Jun 2021 07:22:34 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id g7so2253724wri.7 for ; Thu, 24 Jun 2021 07:22:33 -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 x1sm3202870wmc.31.2021.06.24.07.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:31 -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=XdJG7ZIE4+jGMuoiadGQKywOCCIK+dcTPMT2LT+HY3I=; b=PizqlPQ8uywdsFLvuXLK0lfJJ0AhVrrqPVbHHlSOtjmPLZ65gg1I/uCKCpquDEPNW3 oMY/LwXYW1+pyGZTssLvgX89mC71Jy2MtJWVCSlrxDnRnp5Dj3YUyfb+Q05fFSUrIIQW Twsyx62T7n43kFtxOtt27yuWNtvFEOcykN+ZL3aJBvK/sCEEE+r7I7DBG2mMR+enKt4E l1+O4mEfXUbLaYITlsGyqbeAxXKPK+PC8WqLrMPodPNdQG7W7U2DKWlNRzyhFsvvvzJR Tw7IxkNRYpF5/vmnZiu9QjZ4KqJsiKbtEFOznfIQQYestBoXHo4yhQzMMm2lztGOBrqR uRFw== 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=XdJG7ZIE4+jGMuoiadGQKywOCCIK+dcTPMT2LT+HY3I=; b=H5B8TFt9706VfD5kq4dkQN+CUki5H2RA0OpQvbVWTVrNnp1RvQQ1okSnQPsEvbCQFu syIt0gSTceRdiI2r6kVJVYRI9OFKE9GS4UWVEmJa/e9gXpR2OxMNbA8bcELGAqJtbzLc E6CZSeFHUOCrV2FHlo9vSUzE+TxdT59XAV7nEb57ZdJSqqwQGpvpwlExyTeQ/b8NhU+c 85TmDXfSRSZCGRc8vodXx39RlEOmY5R/mZv8K6OOPYLaPPgIyuTgYi5EQKBiPkqb9USg bc5v7oVhMB7WLhm5Urp7M1UhoP95xI4GgYzCoTayK087FsUou5FMz3CF5sKntoQRPkVq vHpw== X-Gm-Message-State: AOAM53247ORPY/EGHr5gX/8dhpwe3yRupMgyRpTvj5oAmxN4K4UPczFO oC67VlbqYiNonhf8xyTDR0w= X-Google-Smtp-Source: ABdhPJyyMUx++MFu9Ddwr7bJVCNwpX8iHwKaCj/f4kznu1Yet9eeB2O4NyD8ZWcRk0djvvOUtLek9Q== X-Received: by 2002:a05:6000:1091:: with SMTP id y17mr4907241wrw.100.1624544552345; Thu, 24 Jun 2021 07:22:32 -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 04/10] hw/sd: Introduce sd_cmd_handler type Date: Thu, 24 Jun 2021 16:22:03 +0200 Message-Id: <20210624142209.1193073-5-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) 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=C3=A9 Reviewed-by: Bin Meng --- 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, }; =20 +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; =20 struct SDState { @@ -994,6 +998,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SD= Request req) return sd_illegal; } =20 + if (sd->proto->cmd[req.cmd]) { + return sd->proto->cmd[req.cmd](sd, req); + } + 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 |=3D 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) { --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) client-ip=209.85.221.53; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f53.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544559; cv=none; d=zohomail.com; s=zohoarc; b=ROS033Wp8R5K694yFn39hgwm2WAvQE/gu9bBt3rdSYLe/haOTyDb86zJBm3ueaRWb1uOuua9xB0onwDYFfM8Njw2BNFPlH840dN2VnwWw8/drkUg5spVGNyoLqFfQnsPmDexHi25wIxP8S3yRZv4hcAwzsDygCvi3o0lJAAhp8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544559; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JzqeSaa2O8XzfBmvOuh3ggwx7gOwVaB9JI3bIWkBQOI=; b=PAZ//mwRMH4ri5SYmJH6BgyqrwYQHXDfa6a7QGHFpCjVDl6CoL4TzQYf3kKJcLrPyNPSwnr1x9G0PMTLDo51c1n7CaJHuLSHA5jS7e1PEwihYbZ5TW3yqEh0m+r+ueKDyRVxL3l7aWadGGslfWJTTlDFgtFQc4Wu4cjgckF80uY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by mx.zohomail.com with SMTPS id 1624544559041744.9124735208952; Thu, 24 Jun 2021 07:22:39 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id l12so6165364wrt.3 for ; Thu, 24 Jun 2021 07:22:38 -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 2sm3286158wrz.87.2021.06.24.07.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:36 -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=JzqeSaa2O8XzfBmvOuh3ggwx7gOwVaB9JI3bIWkBQOI=; b=rT+8FbYdzjYOERh5QdxCXMLZM7gJkx7gRMCjFLq7CMOWHKvrn7N/fcn1tUZJ+z2Pm3 pVNIrANLuKwKqfHGusnFGUHliHOeYKyp2B7MZFhXKTRsb9RMHFOTBVt7lQRfwUTNTsF+ hvoZDTkMFynlOplE8lhavYoedsHDr601JPqOk60up2jV4ALwojtAIVSz2qnt/4ihZ2UR wkwj5H3IAwXbSFixJOsFs+d/A+fvDKqZKk/n815PRXIm7pUhfCS7IePMpIMmHwGDgioB 3YR/mLZBGp3B1EdFuYnjDsXgpi6a2nfFoZRU2uJAAVlycNwQllm9Jb42u5MMK9VSfBgr V3sg== 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=JzqeSaa2O8XzfBmvOuh3ggwx7gOwVaB9JI3bIWkBQOI=; b=TejvqrUYHfz50xO+CSN9+DjznFbDb9hqzCxSZE7sTNJUX3CDS0hhuMcNkZOisV4ICu lXjzon6tluCCzsLHhAyCzMnjeEGp8rCbxbYHBJwSJU8VG32KCdnCBjO6/f8jG9BEpgED VP2Boqlnb0ioVsbSM3qSHWDjq7C6BHprN4/vtdFbqJWkrNFeQpMRWTjZhwySDMx/NcgN 3zUVYe5g5Knkd4LbGVWA30Qj4Z/y0IEj1Paiwk0+4MuVtcEfbz22kt3aSxe8/HKniYoR pm2UuFb56Im3kKmurZ7RP4DeYuREAdo43xPGi/fLptEsSPJpZArvl6V00h0rDwsOHlw1 IVSw== X-Gm-Message-State: AOAM531PAN4OLfQUXHB1A+lDc9TxvGgnxV3lIs34UCDZyCDImjkxwodW jeAczFPcw50dFlFogJtSeHo= X-Google-Smtp-Source: ABdhPJy2gQrbHUDzdMDCZe9VPbrEyHH+ESNy4jffUGRaycnYvqZFXBqxGLpLjdP1AgEjLd3wctgdrg== X-Received: by 2002:a5d:6208:: with SMTP id y8mr4777971wru.386.1624544557276; Thu, 24 Jun 2021 07:22:37 -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 05/10] hw/sd: Add sd_cmd_illegal() handler Date: Thu, 24 Jun 2021 16:22:04 +0200 Message-Id: <20210624142209.1193073-6-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) Log illegal commands as GUEST_ERROR. Note: we are logging back the SDIO commands (CMD5, CMD52-54). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 57 ++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ce1eec0374f..0215bdb3689 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -965,6 +965,14 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState = *sd, SDRequest req) return sd_illegal; } =20 +static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s: Unknown CMD%i\n", + sd->proto->name, req.cmd); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1017,15 +1025,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) break; =20 case 1: /* CMD1: SEND_OP_CMD */ - if (!sd->spi) - goto bad_cmd; - sd->state =3D sd_transfer_state; return sd_r1; =20 case 2: /* CMD2: ALL_SEND_CID */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_ready_state: sd->state =3D sd_identification_state; @@ -1037,8 +1040,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) break; =20 case 3: /* CMD3: SEND_RELATIVE_ADDR */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_identification_state: case sd_standby_state: @@ -1052,8 +1053,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) break; =20 case 4: /* CMD4: SEND_DSR */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_standby_state: break; @@ -1063,9 +1062,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) } break; =20 - case 5: /* CMD5: reserved for SDIO cards */ - return sd_illegal; - case 6: /* CMD6: SWITCH_FUNCTION */ switch (sd->mode) { case sd_data_transfer_mode: @@ -1081,8 +1077,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) break; =20 case 7: /* CMD7: SELECT/DESELECT_CARD */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_standby_state: if (sd->rca !=3D rca) @@ -1212,8 +1206,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) break; =20 case 15: /* CMD15: GO_INACTIVE_STATE */ - if (sd->spi) - goto bad_cmd; switch (sd->mode) { case sd_data_transfer_mode: if (sd->rca !=3D rca) @@ -1320,8 +1312,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) break; =20 case 26: /* CMD26: PROGRAM_CID */ - if (sd->spi) - goto bad_cmd; switch (sd->state) { case sd_transfer_state: sd->state =3D sd_receivingdata_state; @@ -1466,15 +1456,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) } break; =20 - case 52 ... 54: - /* CMD52, CMD53, CMD54: reserved for SDIO cards - * (see the SDIO Simplified Specification V2.0) - * Handle as illegal command but do not complain - * on stderr, as some OSes may use these in their - * probing for presence of an SDIO card. - */ - return sd_illegal; - /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ switch (sd->state) { @@ -1515,19 +1496,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) break; =20 case 58: /* CMD58: READ_OCR (SPI) */ - if (!sd->spi) { - goto bad_cmd; - } return sd_r3; =20 case 59: /* CMD59: CRC_ON_OFF (SPI) */ - if (!sd->spi) { - goto bad_cmd; - } return sd_r1; =20 default: - bad_cmd: qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); return sd_illegal; } @@ -2114,10 +2088,25 @@ void sd_enable(SDState *sd, bool enable) =20 static const SDProto sd_proto_spi =3D { .name =3D "SPI", + .cmd =3D { + [2 ... 4] =3D sd_cmd_illegal, + [5] =3D sd_cmd_illegal, + [7] =3D sd_cmd_illegal, + [15] =3D sd_cmd_illegal, + [26] =3D sd_cmd_illegal, + [52 ... 54] =3D sd_cmd_illegal, + }, }; =20 static const SDProto sd_proto_sd =3D { .name =3D "SD", + .cmd =3D { + [1] =3D sd_cmd_illegal, + [5] =3D sd_cmd_illegal, + [52 ... 54] =3D sd_cmd_illegal, + [58] =3D sd_cmd_illegal, + [59] =3D sd_cmd_illegal, + }, }; =20 static void sd_instance_init(Object *obj) --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.54 as permitted sender) client-ip=209.85.221.54; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f54.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544563; cv=none; d=zohomail.com; s=zohoarc; b=EL3gkppaqDJC3UvI5Ma6dDC2A1p7V7eqnGIRTurh4LDJIwWbXd0DEy3wqJz93QZy1zfNwfeJzW2bqxVQtsFSLlWa5JKEgkswEc0KspOMXfHQHVQXCs22qIEF9rzfbMRPotZ4zQ4zhdLtUN4UVGxAvzqpz9k8LqBlLSReJCA1tio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544563; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZYvuxt0NCh8Bn052rHsHuAYilMYeW5qZBoGZhPd54Lk=; b=X2XO9pXT03DH81iEM8K77s/sMpOi7zNuWZ8DwjVjFpJqv6dicjy0bM0Wtyjg6cXRNMT41zlQ4n8w5YXijsBeCxAy79/ZpoItXbt8ImL+tHGZ735UPK8FulVNkoUOmGSzPw3uZB0qEC6v+o/b9sg2BK9EACL3wvkmoy2V5mDdg+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by mx.zohomail.com with SMTPS id 1624544563849483.62109582418645; Thu, 24 Jun 2021 07:22:43 -0700 (PDT) Received: by mail-wr1-f54.google.com with SMTP id g7so2254277wri.7 for ; Thu, 24 Jun 2021 07:22:43 -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 c21sm2942022wme.38.2021.06.24.07.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:41 -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=ZYvuxt0NCh8Bn052rHsHuAYilMYeW5qZBoGZhPd54Lk=; b=skZ0/5UWRUEmo3J7TzGc/hC0AHrRKuifqYpEYYl+mkD5KsAzIwHWlWwnDm7LWCkMwI Pe1la39DWaewBK5wghXe0pIEKfhZXPKHka+QDFTsMYWzlf1fJ6l0iw9vXSh35v0WaNXB vQDO5bqL7ieyE210bJyV6oKjgxDbCEZJnJFdLw6butoRbSyAjKu8qvXyLwGPAbuQUVjX 8OVvGjao1Zs9Wc2+XYbQtSMORkF2GkPKyKofffkJMdmshaYmxddcknJmyielM5o2Gh6x mbpdHQZN8tuOvHdOi83oe9gr0C0sizO0TPlUeLPXvqOItLU0lr2UhM/pCUtZKj9SxlV3 G60g== 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=ZYvuxt0NCh8Bn052rHsHuAYilMYeW5qZBoGZhPd54Lk=; b=osihOGsPwNVAB2wf5G3tDcbz8uSEdXaKIGRf1qAYWe3FF0OYZSFtAUaHhHm5Xon1kU NpoPJFqg4m7QCFcQ9EJ8CrSIqgWEtLtnpH1k+IxhVu+g25Atc3Eke4/l+bX4X3atoZ3l HlPPZZ16NMyQmiXAhYzo0pamlM/DY0zQ0rR1qUoYHq3ps0GYLqPprHXFZfW3TES7HH/A s9hmBE+mMZt0ESRXrMXjbn/ZnSusBGr6QF7k+w644CIjjIjYBqFn4MpO1uqpO9fcudug sSwO2uSpHlz8jjiWhJOHylWeXJUVbBCAvdvQ/H0z/cLhQncZLd5P36ZH5EsjjbOfKl7p /cxw== X-Gm-Message-State: AOAM531cprTqQrSHZhbLR479KqZmrc04ySASG0u1u2t2h8hLfcHUxUMi hjS4rUrsJTqy8RL3u7Nk0LM= X-Google-Smtp-Source: ABdhPJycTAx3L7vZcldgxhrMz4ec+gyuuZvY1whVcMOolmHdGuaVqCJ2HrCVt2/OOZniHWBqVG9ivg== X-Received: by 2002:a5d:680c:: with SMTP id w12mr4814139wru.142.1624544562084; Thu, 24 Jun 2021 07:22:42 -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 06/10] hw/sd: Add sd_cmd_unimplemented() handler Date: Thu, 24 Jun 2021 16:22:05 +0200 Message-Id: <20210624142209.1193073-7-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0215bdb3689..2647fd26566 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -973,6 +973,15 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDReq= uest req) return sd_illegal; } =20 +/* Commands that are recognised but not yet implemented. */ +static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n", + sd->proto->name, req.cmd); + + return sd_illegal; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1522,9 +1531,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, =20 switch (req.cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ - if (sd->spi) { - goto unimplemented_spi_cmd; - } switch (sd->state) { case sd_transfer_state: sd->sd_status[0] &=3D 0x3f; @@ -1655,12 +1661,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, default: /* Fall back to standard commands. */ return sd_normal_command(sd, req); - - unimplemented_spi_cmd: - /* Commands that are recognised but not yet implemented in SPI mod= e. */ - qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", - req.cmd); - return sd_illegal; } =20 qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", req.cm= d); @@ -2096,6 +2096,9 @@ static const SDProto sd_proto_spi =3D { [26] =3D sd_cmd_illegal, [52 ... 54] =3D sd_cmd_illegal, }, + .cmd =3D { + [6] =3D sd_cmd_unimplemented, + }, }; =20 static const SDProto sd_proto_sd =3D { --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) client-ip=209.85.128.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544569; cv=none; d=zohomail.com; s=zohoarc; b=C4jVQiFCFsjzWqVgsvlK8g9iTWyFrOnuzFStRoohhvN9H5pLVStlS4Qv68/fmE+0kKWnZaMwKGul1MYYVNyLoIzq9h39k6pDir+XO07EjwiE1q6TE+K5jXqRTI4du83I7WvX+A5c/Wj/j4EuzwjTAnscda0dau1vehIDbv4p6bs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544569; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t2T5QOlfHrf7iG9/cLfyY3m+tgUgjAHfpuMa4aQXuhE=; b=Dv0LwTB95feUh59L3QgdU686034faNUD5qK8bbC/MbQP0m+YKRuqwFJsEk5IN3ze3k1ZtlP8FgmHJ7yEQrCN9yFDGEc8XCUOCWgLXue925o8COImux52TqzmtJJ/0awVQ7dijxWMOWw66hDWZlZuR1ttIHsqgLcHM0ONRChkhr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.zohomail.com with SMTPS id 1624544569304503.9150321395439; Thu, 24 Jun 2021 07:22:49 -0700 (PDT) Received: by mail-wm1-f51.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso6370258wmh.4 for ; Thu, 24 Jun 2021 07:22:48 -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 12sm6965377wmj.12.2021.06.24.07.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:46 -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=t2T5QOlfHrf7iG9/cLfyY3m+tgUgjAHfpuMa4aQXuhE=; b=pZK+OxXsw7rulKYQ+x9wUUXA4wmeLQgxKF4hLdhDvnTRLSrdKjTHQfgTMQ9h6kZlzZ JFhbYQThC0R3Bnd93pk+G6dn+HRHzuYR0ecxyqNHiQL4LinmIuzpYJJ59pyaUASPqbms lljuGdAOXtPkCo3vbZ0r6/OsiWgWpa1kIk0M5cdWDD642rpSjJeiwlQ+hbyOaof7g+L6 XfRya3qV5+cf+f3tHqzgPRdgdf6brNxCmeCVTnY6hA/tWMlqDo51SeYqQT5+1CjSPlJb PUc+sxpRsKG96d0/mNOMHfoD04hZxQ+iMDuZc+bUsZjTu8AgGLboc5ybIekhTwmjRsaD yNxg== 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=t2T5QOlfHrf7iG9/cLfyY3m+tgUgjAHfpuMa4aQXuhE=; b=n5xLNIdRntaai8hcjwRO0px4GoLtHqRb2IIx7gq8BGeBwxFLrD5kuV4e1tHFMLnCbV mzNdECfiwVHNlBmyX81Tf84sj77T5Ai7T3RhcOkgwr8TP5HkVTvL2INimpeNQJOPvOpd HFq/V8CunVrG9RdSsmNjAuhOLgJalg8vnaUddp6bKTlbS13xw3r0s6TF0/onVmvx7OeF 5j2Vp+s1upDCy9hbWO+D8u3d/tp53zdQmrvuar9NQL/2aUSz9+w7kwmkOxeJ4bnqGku3 cRerzNYsiNnwr8YYzAat6iEBgHWQ8OspR7l12Ik299BgEbrf686eBRGRT3BYRPdXV21B PrIw== X-Gm-Message-State: AOAM530JtMfUvxX5dIH2qTnJ1+o97IMa2vSF1yBkcjviT6PbL4v4Fcff uHrmEn5reSP8DpIR9GEKPf0= X-Google-Smtp-Source: ABdhPJwX/d9F44h/H3fJPc3Pl7hu+ZBQexi1MfAoSkjYBSC2yDO48tO9JFqn98OSv5eCiUM0YFeaLg== X-Received: by 2002:a05:600c:4642:: with SMTP id n2mr4605130wmo.101.1624544567562; Thu, 24 Jun 2021 07:22:47 -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 07/10] hw/sd: Add sd_cmd_GO_IDLE_STATE() handler Date: Thu, 24 Jun 2021 16:22:06 +0200 Message-Id: <20210624142209.1193073-8-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2647fd26566..3ef6aca89da 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -982,6 +982,16 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd,= SDRequest req) return sd_illegal; } =20 +static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) +{ + if (sd->state !=3D sd_inactive_state) { + sd->state =3D sd_idle_state; + sd_reset(DEVICE(sd)); + } + + return sd->spi ? sd_r1 : sd_r0; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1021,18 +1031,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) =20 switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 0: /* CMD0: GO_IDLE_STATE */ - switch (sd->state) { - case sd_inactive_state: - return sd->spi ? sd_r1 : sd_r0; - - default: - sd->state =3D sd_idle_state; - sd_reset(DEVICE(sd)); - return sd->spi ? sd_r1 : sd_r0; - } - break; - case 1: /* CMD1: SEND_OP_CMD */ sd->state =3D sd_transfer_state; return sd_r1; @@ -2089,6 +2087,7 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi =3D { .name =3D "SPI", .cmd =3D { + [0] =3D sd_cmd_GO_IDLE_STATE, [2 ... 4] =3D sd_cmd_illegal, [5] =3D sd_cmd_illegal, [7] =3D sd_cmd_illegal, @@ -2104,6 +2103,7 @@ static const SDProto sd_proto_spi =3D { static const SDProto sd_proto_sd =3D { .name =3D "SD", .cmd =3D { + [0] =3D sd_cmd_GO_IDLE_STATE, [1] =3D sd_cmd_illegal, [5] =3D sd_cmd_illegal, [52 ... 54] =3D sd_cmd_illegal, --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) client-ip=209.85.221.46; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f46.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544574; cv=none; d=zohomail.com; s=zohoarc; b=XNKb6rNRzbyKf8ij6/AFBd4G3VWpmWCm63X923ZZQ3NJ44r6RhA1L4Z+OcMd4L0f5fwMUI+bDnqC1dconbogG8mMZHmqmrHHmlV8f2TXpBIO+pv9pC6nS9CRJQDBQhGHRhTH+8cvdoFKZOcgZjAguLn/mXA2kNYgHgpwHeCABUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544574; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N8335+v657OPgDsK3i2XqXKBZf94tMX7vRL29WozTPg=; b=ZIlLAprgYF+c6Wx8TZkxA4AChpIR8qAkX8nmvsBqbn86QqqHmLoLOAWnk96MN7mvwv3rZa939MRAWfRrszHEJzNIfHqWsWPVUcBB8qcLXBiuPWHEHSJcdWzymgcFFAAQGW31EAso8BMvnZ+U2IpfH/VE63B9cankw56UE1ymoP0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mx.zohomail.com with SMTPS id 1624544574105684.7217491790096; Thu, 24 Jun 2021 07:22:54 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id e22so6905354wrc.1 for ; Thu, 24 Jun 2021 07:22:53 -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 n65sm8621361wme.21.2021.06.24.07.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:51 -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=N8335+v657OPgDsK3i2XqXKBZf94tMX7vRL29WozTPg=; b=CLkN++yy9BXjHS2qH/B5E95OKZWRRN5saro1Wf67AuLEMJo80tNEDmLr7Ors8xQVQW VAFQDjLbYTsCupcrb4H9b6h5INNz+KFfBRqkopRrQ9yAiNbvhfoAQrfizky855FaJK7J lKMu5t6GX7wm5l3rOmcICtIGpR/4QXxhZngR6fadN4/7TkcYbD16qPMQcM0cqDd/M8Ci +pgRt6PIdlj7k432Em8ha+eVISpAvgA1Bl5o84mV4TtBfw0oFMV7hpB+fMKniFj/r63L yOeLo15mF+bAXJOGHZU0TTiyglcT2z0GMP5wpt6tDduShI7Hv3h+SYu0mRgBPMk5uwzv PJvw== 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=N8335+v657OPgDsK3i2XqXKBZf94tMX7vRL29WozTPg=; b=fbe5/7TN2Hs6GYopUA5v3M7PpwBKUqVqYsadzrmmNRjNbf9bbhslfUnpi+Yp2d7yd/ sloSB2LHDJl+pU7eu2hC9pTVPqe6oIhO0UK6E/e0XSFMCt+TIGHqG39NI2rLnQpU3E5f JTUmlbd6RZv8jXLyoIpKw9rcNuAHAuLDopSQzFDevVA0S+vUBZqyu57hIQMDlOAV0fs+ QMkC73rgPxNKmwtz0ZNOIeWPzvPerpe94Sq5a/ItduZBHj1pC1Oyz5bej2nB8jd9LWRR MTBWjJm1h4YUJkyjX6SwEa+tIHhmDZXpjlHPhULZpAPCW5DE3ArL0gLEyZoifXOuxhUb FoMg== X-Gm-Message-State: AOAM532obhGTCiTS7DPXe6g46o52PfdlnN4aXzeogNjT6wYZH8AOi9mE szulBbEghDvulMXmmfLugpg= X-Google-Smtp-Source: ABdhPJx2tqlVjvLafFwiH8HczgnO6SstZ8R4E6rKVkEhI2aXimHZmll8dQtjHLJPJfODTdnMoMrEcg== X-Received: by 2002:adf:e112:: with SMTP id t18mr4847275wrz.46.1624544572324; Thu, 24 Jun 2021 07:22:52 -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 08/10] hw/sd: Add sd_cmd_SEND_OP_CMD() handler Date: Thu, 24 Jun 2021 16:22:07 +0200 Message-Id: <20210624142209.1193073-9-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3ef6aca89da..b63d99f7da0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -992,6 +992,13 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd,= SDRequest req) return sd->spi ? sd_r1 : sd_r0; } =20 +static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, SDRequest req) +{ + sd->state =3D sd_transfer_state; + + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1031,10 +1038,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) =20 switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 1: /* CMD1: SEND_OP_CMD */ - sd->state =3D sd_transfer_state; - return sd_r1; - case 2: /* CMD2: ALL_SEND_CID */ switch (sd->state) { case sd_ready_state: @@ -1579,11 +1582,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, break; =20 case 41: /* ACMD41: SD_APP_OP_COND */ - if (sd->spi) { - /* SEND_OP_CMD */ - sd->state =3D sd_transfer_state; - return sd_r1; - } if (sd->state !=3D sd_idle_state) { break; } @@ -2088,6 +2086,7 @@ static const SDProto sd_proto_spi =3D { .name =3D "SPI", .cmd =3D { [0] =3D sd_cmd_GO_IDLE_STATE, + [1] =3D sd_cmd_SEND_OP_CMD, [2 ... 4] =3D sd_cmd_illegal, [5] =3D sd_cmd_illegal, [7] =3D sd_cmd_illegal, @@ -2097,6 +2096,7 @@ static const SDProto sd_proto_spi =3D { }, .cmd =3D { [6] =3D sd_cmd_unimplemented, + [41] =3D sd_cmd_SEND_OP_CMD, }, }; =20 --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.49 as permitted sender) client-ip=209.85.221.49; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f49.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544578; cv=none; d=zohomail.com; s=zohoarc; b=HEdR/sVh8wu8w9yvWoYYHgPspJgyIi8cSbq/LV1OG8KMdYRTNfOmyz782QCp/RSZvP4t/OklVfjUqK74ukwdj2VWvrsH3XVhArl2GyVJlkXfIEq33RcQHG9o7jBhuM3x9zD8MYd4Akzip0MPzynn3ieMHWVMyx2I744Ho4Y8a0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544578; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BVxnyFp5X4RvfAz2vnlIan698SUObGu/Nhwh+sEDGac=; b=nXY5svRxkKYd3wE00t8z3J4KBaueYGuaSZ3MZ+RgzfxculpkLeW3Yv90WvEiQ34eH26f7Ncik00TZPvrJqMzBqcBpqkmGYbx9kukNRQaz7Y75rwKTfy3tqlqyAQ9XujaXiC8vawkb78gC0IMb18fjKukhZFpnq8zpFX6iBLxh7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by mx.zohomail.com with SMTPS id 162454457885286.79520035429766; Thu, 24 Jun 2021 07:22:58 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id i94so6900635wri.4 for ; Thu, 24 Jun 2021 07:22:58 -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 2sm3286882wrz.87.2021.06.24.07.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:22:56 -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=BVxnyFp5X4RvfAz2vnlIan698SUObGu/Nhwh+sEDGac=; b=WhK6ZkefnVJUiJs7Q+1UM0lAaxjsCTUvjhKZuwh/neGP3YjWBpAzJ8VNaaFWi30XBh ysyEj+34Y0sdsRyHG34XkwRL9HNTGzZCu/6EiCzDPCtbleIdBeZJy4Kbut4nlOq7hw+Y sWQ2cQeVdgP2sq+eVoa6bHC0d+7AeLGfzxmOwxCF6TCBqZzixCjXbbDSNEHyv/ZWwa1c UUR2Q6Y0qn6bh7/SibUpHVfamlRsDfnmtuX6cRfOVwumvQmm5nADs2mTFFvS5LmCG7qr sT0TmklwnwvBTZOeESc4uqzEE362xcHgUO6lVB+10dMWAi1GHMmocEpZMDSTBbmww/WJ R+XA== 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=BVxnyFp5X4RvfAz2vnlIan698SUObGu/Nhwh+sEDGac=; b=Pdpi4t2V/D/EG18n2+AYbytHqR36oMVfQ8zMljowyXTDdJGAe1/ldeDP7qrun2nMm3 1Sl/IUqj/nvZBX42/YTzkRIeqAZgCZbBjWvH/5zsDtZ8aQsWA6gQOBP3c0Nebm3wIL4O ix/7Q0/8exQZxqsus9x6iZ49CJ/TiboHLEAhb4ggg9SvUnR8/DxKxOrgh+Zmvzma+6Pr rq7X/k7i5qB/TTXAXyd28kk9ueo3wA8VSFX+z0hkBAv3v8S7OMRQGujHDRSUvS4OVmNZ Xc9wC2ATEWLghiB1tTpis8s+ltWor7Gb0pYVwakN4lN+eNX/GtRfhlpw+jgbYyjCGrCI X3ZQ== X-Gm-Message-State: AOAM530QEF793X4AV4jigjsF8u/Q66oXmgmOrc8lmuLK7NbU+ltq1A1f cfU78ZGhUF6Go/ury2GXrT67tOv3COX6Rg== X-Google-Smtp-Source: ABdhPJyZ+JFNU+nEyUcFLAc7xjhTk3YRbK5fq1M1IrZDNGVV7W6mXO27YOd4QSIS0II7V5tsWBl34A== X-Received: by 2002:adf:eacc:: with SMTP id o12mr4845878wrn.3.1624544577177; Thu, 24 Jun 2021 07:22:57 -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 09/10] hw/sd: Add sd_cmd_ALL_SEND_CID() handler Date: Thu, 24 Jun 2021 16:22:08 +0200 Message-Id: <20210624142209.1193073-10-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b63d99f7da0..70dde5ae0b8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -999,6 +999,17 @@ static sd_rsp_type_t sd_cmd_SEND_OP_CMD(SDState *sd, S= DRequest req) return sd_r1; } =20 +static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req) +{ + if (sd->state !=3D sd_ready_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->state =3D sd_identification_state; + + return sd_r2_i; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1038,17 +1049,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) =20 switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 2: /* CMD2: ALL_SEND_CID */ - switch (sd->state) { - case sd_ready_state: - sd->state =3D sd_identification_state; - return sd_r2_i; - - default: - break; - } - break; - case 3: /* CMD3: SEND_RELATIVE_ADDR */ switch (sd->state) { case sd_identification_state: @@ -2105,6 +2105,7 @@ static const SDProto sd_proto_sd =3D { .cmd =3D { [0] =3D sd_cmd_GO_IDLE_STATE, [1] =3D sd_cmd_illegal, + [2] =3D sd_cmd_ALL_SEND_CID, [5] =3D sd_cmd_illegal, [52 ... 54] =3D sd_cmd_illegal, [58] =3D sd_cmd_illegal, --=20 2.31.1 From nobody Mon Feb 9 15:58:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) client-ip=209.85.128.42; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f42.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1624544583; cv=none; d=zohomail.com; s=zohoarc; b=eRTdiRANXv/z9O+AILbl738x3y6tHzG3So1ukSkQJNe63Zf3fY+70yyOQa3rJ7RwpXGr6AoUOt3TSrGlkmSLRbD0MVlYFAZOU3AiH3edRRY1zvmldN9MLfVj032SydWSrTzLLvJClE4fek76qssSVjYZjCtZIcGgjihz+LEbV/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624544583; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=odL4aPXo6G2NwNk7zPq0Akb4FqD4x5f/HsxoI2Fk9O4=; b=i0THalvdobHWH+WS+Ecx79q3rdB5+afuanGF4Z7QLHbtNM1C5Vn5BT3m2pFV+WDpF5zKW3x+3OEKiVNrJy6+HHhM5IOguXAXdLo0TMmR2stnxg9cS/i0zSGcTf1WuJwhaJwemOYvjpn0/8tfvIWqHsLzLS1XRj6nDYJ/RYXoMTc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mx.zohomail.com with SMTPS id 1624544583867212.7093483681474; Thu, 24 Jun 2021 07:23:03 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id m3so4096479wms.4 for ; Thu, 24 Jun 2021 07:23:03 -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 f19sm3287382wre.48.2021.06.24.07.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 07:23:01 -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=odL4aPXo6G2NwNk7zPq0Akb4FqD4x5f/HsxoI2Fk9O4=; b=nwSHVBxvN19K6hEKysa0F/1wEeCA4nNxofX3HG8Hld4rxyJTjGzK0aLJGTmEcfjPqC Bu9lExkcH94jGRqoFuA63qhnUuuE4KfMxL3ypep6aaGIdWUFi8O2aX6rdqFdMXlBmvGo 5oK58JukEhlXvvObg3GrGw5QOPTkA8jcLHDKBpXOO9gDm80mMOd8OUYLE6Zo4pZ7oJnc JZGEETznUgUM8d22gxKSFdfj52iE1hl4TgcAFthqpeC0TLJVmOE+8p1wHYFGVP17eIXk IhNYH9wwttQfrL9XlhBvzJs9/5BnPlIV7q7Q69DpSaAHPaZmW3DDDMU4ErQg9xlZ8OTV 3pRQ== 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=odL4aPXo6G2NwNk7zPq0Akb4FqD4x5f/HsxoI2Fk9O4=; b=kFb+05FY4eju7KSyERNZpq+FdXI5McRv6Lywu6pA3k1a4jDamS8UqOMIQuSaRVt5wS tMi1a7fTB1BrrzRqaYQaxrWl14L6w6XvzjyL8EVKkn/saPunJPyjTiYf4m3Jy1iqFvPf lHZT6IQ+uU8CeQPfcaZ7klR8Xd4a9CfOM8TZdXClDvsjPt4BlqI7V+gLa2BzNbiRIIRT VcqgL1EKq5z/hkbv4961/u7vKuRrHtLv4RXqXFARp3Ax4w0Oppq53+vsWDzEXCg+TddJ MwpTkKLUudR9CV6RW4f2k/dqFIn8YM5TX82Fw4kBBAZboNy7ZLp63p9p0ur5iPPUfxbU 1muA== X-Gm-Message-State: AOAM530EoCSumdfPsTeZPnH3jXgDMIipt2mntEdaGeB3EMmyMYKudXLh Rr8B5XKR/7OaKwMI282yUCz818FNBHFxUA== X-Google-Smtp-Source: ABdhPJx5k0R3g7Bl5ZKKkl8eknVsO7NjOreXAuS9lJPJdQA6ayjudyNZbtfx6ajz4XVzxMUidrCF+Q== X-Received: by 2002:a05:600c:a07:: with SMTP id z7mr4509002wmp.83.1624544582166; Thu, 24 Jun 2021 07:23:02 -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 10/10] hw/sd: Add sd_cmd_SEND_RELATIVE_ADDR() handler Date: Thu, 24 Jun 2021 16:22:09 +0200 Message-Id: <20210624142209.1193073-11-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 70dde5ae0b8..43a59b34ee8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1010,6 +1010,20 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd= , SDRequest req) return sd_r2_i; } =20 +static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_identification_state: + case sd_standby_state: + sd->state =3D sd_standby_state; + sd_set_rca(sd); + return sd_r6; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint32_t rca =3D 0x0000; @@ -1049,19 +1063,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) =20 switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 3: /* CMD3: SEND_RELATIVE_ADDR */ - switch (sd->state) { - case sd_identification_state: - case sd_standby_state: - sd->state =3D sd_standby_state; - sd_set_rca(sd); - return sd_r6; - - default: - break; - } - break; - case 4: /* CMD4: SEND_DSR */ switch (sd->state) { case sd_standby_state: @@ -2106,6 +2107,7 @@ static const SDProto sd_proto_sd =3D { [0] =3D sd_cmd_GO_IDLE_STATE, [1] =3D sd_cmd_illegal, [2] =3D sd_cmd_ALL_SEND_CID, + [3] =3D sd_cmd_SEND_RELATIVE_ADDR, [5] =3D sd_cmd_illegal, [52 ... 54] =3D sd_cmd_illegal, [58] =3D sd_cmd_illegal, --=20 2.31.1