From nobody Wed Oct 29 11:37:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525846068381983.4523914905801; Tue, 8 May 2018 23:07:48 -0700 (PDT) Received: from localhost ([::1]:54700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIGR-00051b-JW for importer@patchew.org; Wed, 09 May 2018 02:07:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIA7-0008RK-U3 for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGIA7-0005PK-59 for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:16 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:45912) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGIA7-0005Oy-0Q for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:15 -0400 Received: by mail-qk0-x242.google.com with SMTP id c64so1793596qkf.12 for ; Tue, 08 May 2018 23:01:14 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id 42-v6sm1707217qte.41.2018.05.08.23.01.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 23:01:13 -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=jr5+WRNGQmZKUpx1I+Oqpv67ZKrD8zNIBtp0rssEOv0=; b=SqM+2CARkX3kRv3Wxtkz8nq+Qw1sAlkB6rCNvP/rX87FRYfssSqdmW3XU3C4oYDOl1 hwKxmXKTHnlXfn70AfxCOM+om1igw6yBxsKY/ty3QRmXnX4qYxr11OjXlA4Is/D9F+/v N+E5WP6v7bgOOCWZGYlAmen7hDz7Mj5C2+F/hDsaanJZt0MCkl3jsLRFaaAO79fVQF07 MiadxrJHVmhnlbuO24Wjb3o22vO+0bboZnplUO3hUrXDGDMGkLgNUkngB5rHdTn0PDMD jaohrIrqbFjoOV06lRRwcodrvY08+14Hh5Ms9fhAhArvVLUCz6jsEPPV5K/5nNsZqCs8 wE7Q== 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=jr5+WRNGQmZKUpx1I+Oqpv67ZKrD8zNIBtp0rssEOv0=; b=KKaxLZ/2vMlBHk3phTnU43VSy6K1J58yiAo1cdWZYWpGVyM+PPf1C9JayEi9wz7+cl eijnsGKjGWhaoLHS1RzoGgUF3VMGmlbrHi0W2wrTX2/W4ZN5zzXkLZvFyV8arBpkLpTw G8lQCmmNpeQnL8aCODJMBUjFIkNpCkLq5yd1r38ZFfsm3sJNE2I6zSrb6LC+AU/fwSFV ll4bBJtTY+3cFk5hVqVwhN1W4DdDDgyu5bbbLdaGyG8lvjKV4hlPvAPcdOmM638rsMmf zjdhBdCE6XVaFIrvQmXLjO/7822myT0MpQ4WfJepQSwKSBmK0xAecpeQHnBSQtVyhHgg Zy7g== X-Gm-Message-State: ALQs6tAgVPu4HyUfS7y0HqdAX9u9sgO4vX1+M28CVXlDbZMMDBTCHUwa ssUbcElC725roCIlVSv/vn0OU3mc X-Google-Smtp-Source: AB8JxZq4gXcufZGJct5MonChSlnM/Lx8x9wT5K95XdBrJFjk9sVosZ1y2tQ0lCD3ZNNOBtDUPVnvgw== X-Received: by 10.233.232.197 with SMTP id a188mr37305772qkg.312.1525845674213; Tue, 08 May 2018 23:01:14 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" , Alistair Francis Date: Wed, 9 May 2018 03:01:01 -0300 Message-Id: <20180509060104.4458-2-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509060104.4458-1-f4bug@amsat.org> References: <20180509060104.4458-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::242 Subject: [Qemu-devel] [PATCH v2 1/4] sdcard: Update the SDState documentation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Add more descriptive comments to keep a clear separation between static property vs runtime changeable. Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- hw/sd/sd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 235e0518d6..5fb4787671 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -90,12 +90,15 @@ struct SDState { uint32_t card_status; uint8_t sd_status[64]; =20 - /* Configurable properties */ + /* Static properties */ + BlockBackend *blk; bool spi; =20 - uint32_t mode; /* current card mode, one of SDCardModes */ - int32_t state; /* current card state, one of SDCardStates */ + /* Runtime changeables */ + + uint32_t mode; /** current card mode, one of #SDCardModes */ + int32_t state; /** current card state, one of #SDCardStates */ uint32_t vhs; bool wp_switch; unsigned long *wp_groups; @@ -109,8 +112,9 @@ struct SDState { uint32_t pwd_len; uint8_t function_group[6]; uint8_t current_cmd; - /* True if we will handle the next command as an ACMD. Note that this = does - * *not* track the APP_CMD status bit! + /** + * #True if we will handle the next command as an ACMD. + * Note that this does *not* track the APP_CMD status bit! */ bool expecting_acmd; uint32_t blk_written; --=20 2.17.0 From nobody Wed Oct 29 11:37:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525846056844631.6095683845248; Tue, 8 May 2018 23:07:36 -0700 (PDT) Received: from localhost ([::1]:54699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIGD-0004ry-C0 for importer@patchew.org; Wed, 09 May 2018 02:07:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIAA-0008TB-DM for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGIA9-0005VM-JZ for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:18 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:39461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGIA9-0005UH-F2 for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:17 -0400 Received: by mail-qk0-x244.google.com with SMTP id z75so26655339qkb.6 for ; Tue, 08 May 2018 23:01:17 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id 42-v6sm1707217qte.41.2018.05.08.23.01.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 23:01: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=sySHqbdW4+jK0YcFeme9hY4GVz00i4tR/AeeOAE6L34=; b=gvI062mwi2Qjcn9bPYpA5KYoZ3+PHqv0TMJNZfKBri+xeV2xbxgauGlJtJyBpvgg6o gHuv8HhLloOKB/9ckWCyACUgoONoNiP+1LolAo0z6f3mMXGm7VMEQUZfmyLo7PZ4mYF3 4k+8jNHkV6kj1x3NJ/1xlHLEWwIpb/4JDSZ1ntnAmzDAWdCQaFGYR3AUUy2ekr2AS8lF ykxLRXZDsIDqXGHRg6LTLCO+TaJWdwfFyC7QNS1dT6XWtjSnAuFAM6eJZFhUujZFaW7b bn7wzYkb1kXR/840AtmY1eiH9qdaEZnGG9h25UPdc0TTOVVoksFt78AXky+5d2HYFDJJ AGkA== 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=sySHqbdW4+jK0YcFeme9hY4GVz00i4tR/AeeOAE6L34=; b=faHGOJoU8ou4L3EYE9352dUTfUlYT/P5ifE2N1dNd239t8cz7my+XIJ13hZe7XisAs /fxdrI8EWdM/UqNQxr4oTaNVTCVOUz6F/DLAedkae23ce2T96nziEfCsQLleu/dCNN7f G8jjde0aOgnA+eVhs/CTX7hS96HU563j6qO9EoVakLwE+MJhc0fGMdPWjdeWVFS9ZOuj 03Jz87KBfw20YgkfQGjlBNilK31Sma/XMbhwPulde1hVhh2kTEgRqQC8QCc7uYTB/eEU n5qYV3xRs4FV7rK/IatgkuCGMqfkM0PGrqLQTmGq/cA39INUxx1HIxPCZUTx6Ge/lUM9 Vw1Q== X-Gm-Message-State: ALQs6tAwsi8nUfa8un945r/mqENf4wabvLaN55oBOENJjqlNc5SexqUW 9LH/wcxCXhFNq3x59CUtfCg= X-Google-Smtp-Source: AB8JxZpx1ss0Ck4T2xy2KCsir8SN5q7f4CsuvBAYdyZMby2O61g/3AxCUk2ykrjmf7PkMi2CI6oWUA== X-Received: by 10.55.132.130 with SMTP id g124mr38743512qkd.226.1525845676694; Tue, 08 May 2018 23:01:16 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" , Alistair Francis Date: Wed, 9 May 2018 03:01:02 -0300 Message-Id: <20180509060104.4458-3-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509060104.4458-1-f4bug@amsat.org> References: <20180509060104.4458-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::244 Subject: [Qemu-devel] [PATCH v2 2/4] sdcard: Correct CRC16 offset in sd_function_switch() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Per the Physical Layer Simplified Spec. "4.3.10.4 Switch Function Status": The block length is predefined to 512 bits and "4.10.2 SD Status": The SD Status contains status bits that are related to the SD Memory Card proprietary features and may be used for future application-specific usag= e. The size of the SD Status is one data block of 512 bit. The content of th= is register is transmitted to the Host over the DAT bus along with a 16-bit = CRC. Thus the 16-bit CRC goes at offset 64. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5fb4787671..24aaf0c767 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -791,7 +791,7 @@ static void sd_function_switch(SDState *sd, uint32_t ar= g) sd->data[14 + (i >> 1)] =3D new_func << ((i * 4) & 4); } memset(&sd->data[17], 0, 47); - stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); + stw_be_p(sd->data + 64, sd_crc16(sd->data, 64)); } =20 static inline bool sd_wp_addr(SDState *sd, uint64_t addr) --=20 2.17.0 From nobody Wed Oct 29 11:37:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525845866717401.0172848801841; Tue, 8 May 2018 23:04:26 -0700 (PDT) Received: from localhost ([::1]:54684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIDA-0001km-SW for importer@patchew.org; Wed, 09 May 2018 02:04:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIAE-00004y-0U for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGIAC-0005cL-IN for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:22 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:45975) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGIAC-0005b0-Cq for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:20 -0400 Received: by mail-qt0-x241.google.com with SMTP id j42-v6so44200191qtj.12 for ; Tue, 08 May 2018 23:01:20 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id 42-v6sm1707217qte.41.2018.05.08.23.01.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 23:01:18 -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=G2Z3qZi9UvSIpvFOl93Ph9HOe2jrgUqjNP1nVSkUTMI=; b=ARyt+N68kwmv2hPiUWAb6hWCwgojnqfm1S3Zm7CupNVTxAwJK8cwYsfpuarx//xbcb cM5pjfmcEdJn2byT3cEcMI7qQcZxIm4pORQawUKlakELdUJr4onyQgfBeBRXAiYEsCYu 9yl9rLN8Z1vGqyD4QBBP1ZJcR7I3eMDDyZe9y8Sc7ROLvmOQAo4y0P4wcWyuJAgzNbPr 2Q0S1yOz+sCfDi2DkVhiPFuxGsg24lSc4FUfFzXG0VsBFttS3JTT09zj0VaaNxGH3Vf2 moaGMJj9EuGBE+xfVHVdugKvaHZb80iZfVZzmTwd5tM9T/6JRJOQyXWU7ZezW8QlkfE3 1ZrA== 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=G2Z3qZi9UvSIpvFOl93Ph9HOe2jrgUqjNP1nVSkUTMI=; b=e1XbBiFeSvT9/WIqKpWBQZhaBs4JzYoEsFRP6A8B/3QSNU301lIdct0ueUvi2Ga8Gq K0DDXeNB68/49B28Mh9f4LUQ4GYbAU1bIIIgPGs3W+XfOqzmTeNCFs64vYRYpPTZNPzb Vodj4tzFszwCjRwu+NreWaJWqS1CO9iTGWpmoOLUY6hUPlQf8G4te2P8ibAuRQ7hJwkb ELbZQNe4nMhfuILac1blbtDVZ3xweVbUZxDr0VteLf2Lyl4Mbezj13qW4ui73Fd0PWgo nPICVGe5QUSGZYPvp1kiiTh719h7F6QKAD8NEwVO1+WViMBdr4D7KqZWUOxZbHc97LM7 w7uA== X-Gm-Message-State: ALQs6tDoPQe8/tmeJFXLCR3JthW8qBHzUrBmBZ2NYNlhn5IB222w7sYA axIXn7pdaAkvM17c0S4H9xwOF9X9 X-Google-Smtp-Source: AB8JxZp0/Btu5i0Cxko+R2KDL3NeXx8EAF9SZ5G6VbGcqMBe2ayH/80nGtI2KQi/rphAx2tdZtRljQ== X-Received: by 2002:a0c:bd84:: with SMTP id n4-v6mr40602259qvg.148.1525845679415; Tue, 08 May 2018 23:01:19 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" , Alistair Francis Date: Wed, 9 May 2018 03:01:03 -0300 Message-Id: <20180509060104.4458-4-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509060104.4458-1-f4bug@amsat.org> References: <20180509060104.4458-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v2 3/4] sdcard: Implement the UHS-I SWITCH_FUNCTION entries (Spec v3) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 [based on a patch from Alistair Francis from qemu/xilinx tag xilinx-v2015.2] Signed-off-by: Edgar E. Iglesias [PMD: rebased, changed magic by definitions, use stw_be_p, add tracing, check all functions in group are correct before setting the values] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 186 +++++++++++++++++++++++++++++++++++++++------ hw/sd/trace-events | 1 + 2 files changed, 165 insertions(+), 22 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 24aaf0c767..d8dd88f872 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -128,6 +128,11 @@ struct SDState { bool enable; uint8_t dat_lines; bool cmd_line; + /** + * Whether the card entered the UHS mode with voltage level adjusted + * (use by soft-reset) + */ + bool uhs_activated; }; =20 static const char *sd_state_name(enum SDCardStates state) @@ -567,6 +572,7 @@ static void sd_reset(DeviceState *dev) sd->expecting_acmd =3D false; sd->dat_lines =3D 0xf; sd->cmd_line =3D true; + sd->uhs_activated =3D false; sd->multi_blk_cnt =3D 0; } =20 @@ -765,32 +771,168 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) return ret; } =20 +/* Function Group */ +enum { + SD_FG_MIN =3D 1, + SD_FG_ACCESS_MODE =3D 1, + SD_FG_COMMAND_SYSTEM =3D 2, + SD_FG_DRIVER_STRENGTH =3D 3, + SD_FG_CURRENT_LIMIT =3D 4, + SD_FG_RSVD_5 =3D 5, + SD_FG_RSVD_6 =3D 6, + SD_FG_MAX =3D 6, + SD_FG_COUNT +}; + +static const char *sd_fn_grp_name[SD_FG_COUNT] =3D { + [SD_FG_ACCESS_MODE] =3D "ACCESS_MODE", + [SD_FG_COMMAND_SYSTEM] =3D "COMMAND_SYSTEM", + [SD_FG_DRIVER_STRENGTH] =3D "DRIVER_STRENGTH", + [SD_FG_CURRENT_LIMIT] =3D "CURRENT_LIMIT", + [SD_FG_RSVD_5] =3D "RSVD5", + [SD_FG_RSVD_6] =3D "RSVD6", +}; + +/* Function name */ +enum { + SD_FN_NO_INFLUENCE =3D 0xf, + SD_FN_COUNT =3D 16 +}; + +typedef struct sd_fn_support { + const char *name; + bool uhs_only; + bool unimp; +} sd_fn_support; + +static const sd_fn_support *sd_fn_support_defs[SD_FG_COUNT] =3D { + [SD_FG_ACCESS_MODE] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default/SDR12" }, + [1] =3D { .name =3D "high-speed/SDR25" }, + [2] =3D { .name =3D "SDR50", .uhs_only =3D true }, + [3] =3D { .name =3D "SDR104", .uhs_only =3D true }, + [4] =3D { .name =3D "DDR50", .uhs_only =3D true }, + }, + [SD_FG_COMMAND_SYSTEM] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default" }, + [1] =3D { .name =3D "For eC" }, + [3] =3D { .name =3D "OTP", .unimp =3D true }, + [4] =3D { .name =3D "ASSD", .unimp =3D true }, + }, + [SD_FG_DRIVER_STRENGTH] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default/Type B" }, + [1] =3D { .name =3D "Type A", .uhs_only =3D true }, + [2] =3D { .name =3D "Type C", .uhs_only =3D true }, + [3] =3D { .name =3D "Type D", .uhs_only =3D true }, + }, + [SD_FG_CURRENT_LIMIT] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default/200mA" }, + [1] =3D { .name =3D "400mA", .uhs_only =3D true }, + [2] =3D { .name =3D "600mA", .uhs_only =3D true }, + [3] =3D { .name =3D "800mA", .uhs_only =3D true }, + }, + [SD_FG_RSVD_5] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default" }, + }, + [SD_FG_RSVD_6] =3D (sd_fn_support [SD_FN_COUNT]) { + [0] =3D { .name =3D "default" }, + }, +}; + +#define SD_FN_BUFSZ (SD_FG_MAX * 4 / BITS_PER_BYTE) + static void sd_function_switch(SDState *sd, uint32_t arg) { - int i, mode, new_func; - mode =3D !!(arg & 0x80000000); - - sd->data[0] =3D 0x00; /* Maximum current consumption */ - sd->data[1] =3D 0x01; - sd->data[2] =3D 0x80; /* Supported group 6 functions */ - sd->data[3] =3D 0x01; - sd->data[4] =3D 0x80; /* Supported group 5 functions */ - sd->data[5] =3D 0x01; - sd->data[6] =3D 0x80; /* Supported group 4 functions */ - sd->data[7] =3D 0x01; - sd->data[8] =3D 0x80; /* Supported group 3 functions */ - sd->data[9] =3D 0x01; - sd->data[10] =3D 0x80; /* Supported group 2 functions */ - sd->data[11] =3D 0x43; - sd->data[12] =3D 0x80; /* Supported group 1 functions */ - sd->data[13] =3D 0x03; - for (i =3D 0; i < 6; i ++) { - new_func =3D (arg >> (i * 4)) & 0x0f; - if (mode && new_func !=3D 0x0f) - sd->function_group[i] =3D new_func; - sd->data[14 + (i >> 1)] =3D new_func << ((i * 4) & 4); + bool invalid_function_selected =3D false; + int fn_grp, new_func, i; + uint8_t *data_p, tmpbuf[SD_FN_BUFSZ]; + uint16_t max_current_mA =3D 1; + bool mode =3D extract32(arg, 31, 1); /* 0: check only, 1: do switch */ + + /* Bits 400-495: information (16 bits each group) */ + data_p =3D &sd->data[2]; + for (fn_grp =3D SD_FG_MAX; fn_grp >=3D SD_FG_MIN; fn_grp--) { + uint16_t supported_fns =3D 1 << SD_FN_NO_INFLUENCE; + for (i =3D 0; i < SD_FN_COUNT; ++i) { + const sd_fn_support *def =3D &sd_fn_support_defs[fn_grp][i]; + + if (def->name && !def->unimp && + !(def->uhs_only && !sd->uhs_activated)) { + supported_fns |=3D 1 << i; + } + } + stw_be_p(data_p, supported_fns); + data_p +=3D 2; } + + /* Bits 376-399: function (4 bits each group) + * + * Do not write the values back directly: + * Check everything first writing to 'tmpbuf' + */ + data_p =3D tmpbuf; + for (fn_grp =3D SD_FG_MAX; fn_grp >=3D SD_FG_MIN; fn_grp--) { + new_func =3D (arg >> ((fn_grp - 1) * 4)) & 0x0f; + if (new_func =3D=3D SD_FN_NO_INFLUENCE) { + /* Guest requested no influence, so this function group + * stays the same. + */ + new_func =3D sd->function_group[fn_grp - 1]; + } else { + const sd_fn_support *def =3D &sd_fn_support_defs[fn_grp][new_f= unc]; + if (mode) { + if (!def->name) { + qemu_log_mask(LOG_GUEST_ERROR, + "Function %d not valid for " + "function group %d\n", + new_func, fn_grp); + invalid_function_selected =3D true; + new_func =3D SD_FN_NO_INFLUENCE; + } else if (def->unimp) { + qemu_log_mask(LOG_UNIMP, + "Function %s (fn grp %d) not implemented= \n", + def->name, fn_grp); + invalid_function_selected =3D true; + new_func =3D SD_FN_NO_INFLUENCE; + } else if (def->uhs_only && !sd->uhs_activated) { + qemu_log_mask(LOG_GUEST_ERROR, + "Function %s (fn grp %d) only " + "valid in UHS mode\n", + def->name, fn_grp); + invalid_function_selected =3D true; + new_func =3D SD_FN_NO_INFLUENCE; + } else { + sd->function_group[fn_grp - 1] =3D new_func; + } + } + trace_sdcard_function_select(def->name, sd_fn_grp_name[fn_grp], + mode); + } + if (!(fn_grp & 0x1)) { /* evens go in high nibble */ + *data_p =3D new_func << 4; + } else { /* odds go in low nibble */ + *(data_p++) |=3D new_func; + } + } + if (invalid_function_selected) { + /* Ignore all the set values */ + memset(&sd->data[14], 0, SD_FN_BUFSZ); + } else { + /* Write back if all functions in the group are correct. */ + memcpy(&sd->data[14], tmpbuf, SD_FN_BUFSZ); + } + + /* Data Structure Version =3D 0x00: 376 bits reserved (undefined) */ memset(&sd->data[17], 0, 47); + + if (invalid_function_selected) { + /* Maximum current consumption: If one of the selected functions + * was wrong, the return value will be 0. + */ + max_current_mA =3D 0; + } + stw_be_p(sd->data, max_current_mA); + stw_be_p(sd->data + 64, sd_crc16(sd->data, 64)); } =20 diff --git a/hw/sd/trace-events b/hw/sd/trace-events index bfd1d62efc..eba5ab7b90 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -48,6 +48,7 @@ sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%= " PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, ui= nt8_t value) "%s %20s/ CMD%02d value 0x%02x" sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, int= length) "%s %20s/ CMD%02d len %d" sdcard_set_voltage(uint16_t millivolts) "%u mV" +sdcard_function_select(const char *fn_name, const char *grp_name, bool do_= switch) "Function %s (group: %s, sw: %u)" =20 # hw/sd/milkymist-memcard.c milkymist_memcard_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x = value 0x%08x" --=20 2.17.0 From nobody Wed Oct 29 11:37:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525846011182640.8081522993604; Tue, 8 May 2018 23:06:51 -0700 (PDT) Received: from localhost ([::1]:54698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIFW-0004KG-D5 for importer@patchew.org; Wed, 09 May 2018 02:06:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGIAH-00009V-ED for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGIAE-0005hF-P9 for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:25 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:41751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGIAE-0005g4-Ko for qemu-devel@nongnu.org; Wed, 09 May 2018 02:01:22 -0400 Received: by mail-qt0-x242.google.com with SMTP id g13-v6so44208071qth.8 for ; Tue, 08 May 2018 23:01:22 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id 42-v6sm1707217qte.41.2018.05.08.23.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 23:01:21 -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=3sOeEMUxVD9ijnVfb/nF73+bmclv+x4ZlWE6oQqP8aQ=; b=uzYDlj+nsNRZbeRNelqS51aLdZaOAjusGjd4iXIqBj9yK+pQaOACQAtWe6gSz7LUK8 L1njUdn7GYJjmiX1nhwv4h4/eMgUEbLjgIcbe/oLL3hylkTBjCIqMDrUM2Xa/yjylEZ1 TCqVATy2n9+o+QMJiaoOe7d2dihB1RmgMa+CYahk0iH4zGqVY9wJyjrXOUj89lB7zmQ5 uW6QT+l+xdECO0UYuxvpxG7RfvmSLJbXfgAx2WDKVH8AIGAfYiQCWsk7fzfQWzStKvf7 z6UJGtLC6L3dCw4TJb2xaGRJLZFdz4VVFJGedxmd6iA/j5Th6/ZBiWChmCqYX5eth/5a Fu1w== 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=3sOeEMUxVD9ijnVfb/nF73+bmclv+x4ZlWE6oQqP8aQ=; b=VCvmlexgzvcLMIoJgWtOTWAneE/LNH4F0IYWe6NDdA8oTSjjdrJ8WSfRh99PbnSqbo WQ8PM2HzP5BRwLTauQRiQJaXbYYErRuctnrWpPYcIZ9Fsxb0BDnSHSPtkGjTaRu9SabN rjKBoEzIF55JXlJi+QSNQ4c5C9nISyPm/HFyRj2VCIdPd6JpM2GDaznnjZTPAcNUN5T2 UCEP9pXAljt+tcyqxcncClmCIyMa+twgn7dlzFiNirzj7LFgU0VLwr3PDvmz4eF8GTWu esOYYxTvPKIry/IuRPLFgokoacP4u72eYtbOVL/TTXXjuAEjAbpUKnIKETwRKghGSUO5 rAww== X-Gm-Message-State: ALKqPweH1cLaiZEHT6oBeTOP+taQfVzNPQS0A4VMEVwfbblXRGkJPoU1 qih2m+SY0fejWntApwXZZSE= X-Google-Smtp-Source: AB8JxZp+ETDDQO3fywHrkNTmzYNwW6J7kUTBAi+6TlAJ+zRGyn5fh9xKbL7o7nyX7AFNYdL7FSTRbQ== X-Received: by 2002:a0c:d108:: with SMTP id a8-v6mr10732327qvh.159.1525845681863; Tue, 08 May 2018 23:01:21 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" , Alistair Francis Date: Wed, 9 May 2018 03:01:04 -0300 Message-Id: <20180509060104.4458-5-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509060104.4458-1-f4bug@amsat.org> References: <20180509060104.4458-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH v2 4/4] sdcard: Add a 'uhs' property, update the OCR register ACCEPT_SWITCH_1V8 bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- hw/sd/sd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d8dd88f872..a0e8a1b46a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -94,6 +94,10 @@ struct SDState { =20 BlockBackend *blk; bool spi; + /** + * The UHS mode the card supports if any, else #UHS_NOT_SUPPORTED + */ + uint8_t uhs_mode_supported; =20 /* Runtime changeables */ =20 @@ -300,6 +304,9 @@ static void sd_set_ocr(SDState *sd) { /* All voltages OK */ sd->ocr =3D R_OCR_VDD_VOLTAGE_WIN_HI_MASK; + + sd->ocr =3D FIELD_DP32(sd->ocr, OCR, ACCEPT_SWITCH_1V8, + sd->uhs_mode_supported !=3D UHS_NOT_SUPPORTED); } =20 static void sd_ocr_powerup(void *opaque) @@ -2240,6 +2247,7 @@ static Property sd_properties[] =3D { * board to ensure that ssi transfers only occur when the chip select * is asserted. */ DEFINE_PROP_BOOL("spi", SDState, spi, false), + DEFINE_PROP_UINT8("uhs", SDState, uhs_mode_supported, UHS_NOT_SUPPORTE= D), DEFINE_PROP_END_OF_LIST() }; =20 --=20 2.17.0