From patchwork Fri Aug 21 14:45:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1349293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EZH+HN4U; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BY48s0r65z9sPC for ; Sat, 22 Aug 2020 00:46:35 +1000 (AEST) Received: from localhost ([::1]:58042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k98JK-00007H-Kj for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2020 10:46:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k98Ij-000072-5L; Fri, 21 Aug 2020 10:45:53 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:41130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k98Ih-0000wm-Cp; Fri, 21 Aug 2020 10:45:52 -0400 Received: by mail-pg1-x542.google.com with SMTP id s15so1093666pgc.8; Fri, 21 Aug 2020 07:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kw0/yVwW5HOT9VWz8EEeWR+3L1WvMdNlQltiSWoKsAA=; b=EZH+HN4UTAkyucRHh8zt2c1WxVspdxTV3VKJXmLu53h1Ye8goiqC6t/INRuA0HhVfk mYbM042/enxCHkVLyn0jG87BnGqFUGdhaaJuHfBwkPAfBQQgs7rA0547dksiTd+61B54 9BF2viSqkSo/HKNGJr8oiLLrCBtg2fFc0uTCPiDJmgk/175PxdWp65drYVQCC9laN3tR 8NSwIFtk4IKQQhpZNQIyS+OlzQkOpMzmaV+4IRZ0GWJi9kx9LJnHogptYSy1zdI/1w0F Ikg28f5B0etMs3jdlDh+ICh7GsbgYrNbAbb8u97ws0MTyrBCiF2xS7crc/O8DEjM+3cF TQcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kw0/yVwW5HOT9VWz8EEeWR+3L1WvMdNlQltiSWoKsAA=; b=F3R8yQnLvzIASFgKPkuK0542cBXjwewE0Y61SwGBLB3tKdUjOuousdK07MT7EW4HBu JbC+wcnU1B7S7BaqALvjm32lVy1lum2XpvhUTlm2ydjleo7WO/k+sMONNvuvh0f2mAXT 2xkBwlboPIjsKdMI2Xvsti9YYFDOicgRrhWbPoINum4lQmyZ6Mad2ycBpQsjS5acXqTY P+4LvqDFHY59cCgvRnsf4f78ufTtbwRZg3nuDGe3jpC1MNRvD3geq4lIGVIP6sGhTn0d LlZ8uptVSmlnFTnaKls4qoJ73TXl7XTFOywxYJ6+tq4qFpM9FvPAsvbbLV8MnoELhrwG eM2w== X-Gm-Message-State: AOAM530huxJTMH7NL7uLF2uZSQ6QTS89aGAtV2Ugzvq/nzp02lnSQbyF eXBVcMtK3x47vhCJZr7BsMc= X-Google-Smtp-Source: ABdhPJyO9YnsRjGdksFLDeEkRECNAJCsepV2QJic6uJ0hlUtD7yRsuMnIYJFgL+s3O0vePobR8CoAw== X-Received: by 2002:a63:f913:: with SMTP id h19mr2616268pgi.427.1598021149579; Fri, 21 Aug 2020 07:45:49 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-146-144.windriver.com. [147.11.146.144]) by smtp.gmail.com with ESMTPSA id s125sm2785702pfc.63.2020.08.21.07.45.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2020 07:45:48 -0700 (PDT) From: Bin Meng To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/2] hw/sd: sd: Fix incorrect populated function switch status data structure Date: Fri, 21 Aug 2020 22:45:35 +0800 Message-Id: <1598021136-49525-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sai Pavan Boddu , Bin Meng , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng At present the function switch status data structure bit [399:376] are wrongly pupulated. These 3 bytes encode function switch status for the 6 function groups, with 4 bits per group, starting from function group 6 at bit 399, then followed by function group 5 at bit 395, and so on. However the codes mistakenly fills in the function group 1 status at bit 399. This fixes the code logic. Fixes: a1bb27b1e9 ("SD card emulation (initial implementation)") Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé Tested-by: Sai Pavan Boddu --- Changes in v3: - add Tested-by tag from Sai Pavan Boddu Changes in v2: - remove the pointless zero initialization hw/sd/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fad9cf1..3226404 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -806,11 +806,12 @@ static void sd_function_switch(SDState *sd, uint32_t arg) sd->data[11] = 0x43; sd->data[12] = 0x80; /* Supported group 1 functions */ sd->data[13] = 0x03; + for (i = 0; i < 6; i ++) { new_func = (arg >> (i * 4)) & 0x0f; if (mode && new_func != 0x0f) sd->function_group[i] = new_func; - sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4); + sd->data[16 - (i >> 1)] |= new_func << ((i % 2) * 4); } memset(&sd->data[17], 0, 47); stw_be_p(sd->data + 64, sd_crc16(sd->data, 64)); From patchwork Fri Aug 21 14:45:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 1349294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VprKKmB+; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BY4BK0107z9sPC for ; Sat, 22 Aug 2020 00:47:52 +1000 (AEST) Received: from localhost ([::1]:33014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k98Kc-0001Vf-Pz for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2020 10:47:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k98Im-00007i-0K; Fri, 21 Aug 2020 10:45:56 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:53886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k98Ik-0000xE-9X; Fri, 21 Aug 2020 10:45:55 -0400 Received: by mail-pj1-x1044.google.com with SMTP id nv17so910307pjb.3; Fri, 21 Aug 2020 07:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vHcIytiPc8HOMvFjqE6nlfonDNLr38E8RDfJfGsnFtY=; b=VprKKmB+XJlTiOCtWnroEMICyLOu4Vc+KepDof0zHhF3gkpCHFb1eQ9zhhuRXutppK VS1gMgUSIkrv0zDJ/pucRBceYYcWnsL/hu7SKXBz/HsKvtzN05HgVyVXrLxgStpt/ehx xCCmA6O8012WjD2IVKAu7m+2KzHsdYXBacuymdgmkVXl7z9iqt5XrGXrA9KofFSjX+2R 1ytgFjvG0/pP6AuWpEMwtbq2JtvVNscugZfn9dmd6y8pKxrtMCRNVZmA0yI0jA/cXZ0h 0UgZFno3Zhi+xTO9ZtWSV8Zj27QQm8m3RRMWFLQUHi+X49xXefOUFy5smJdBsLGw6GKy YQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vHcIytiPc8HOMvFjqE6nlfonDNLr38E8RDfJfGsnFtY=; b=h3nIxWB0QS5K2E/TTXvEWB5yTBrXjUCLn3LHgmWYXgtQrYMkRuRVgEGJDQoWXd/CgR i7OqCUsvttrPUp3+jxbn6Nx88QtANvt8+fAMe/vxobK0vpZ6tux5PMk6TUU6FA1tmQkw NSYgwEr0PYn3KfMCIj1RphhfviOAilj9fSBWw3BHNsl/XU3hbRgUeSeUhMtnW4P1kZkg MWtrDScGTXJP16WxRo7FnP2qKjPnuHbWyj4PjYeypk1w0GWfsDRk7HJxr2jWfGeFBGGI g21ddURowP24lXl/EAxsxnVW86xCWiXjqXibGwWIpvd3J9rJYaPepFkVLY66zhVgIboW cU5A== X-Gm-Message-State: AOAM533Rmg4q2UCJr8rfSB9VhCWoF5H0l+VQmoZjqJsSaWMZ9Krf6Dax 6R2RE+kurnPRHo0gFPLNYKE= X-Google-Smtp-Source: ABdhPJxPpJK7TfjOyIvFnc3aed8DRkFRIiVMdUdU+YMhmBuUX8TFCLHzqJjJrSPj2bKFqkK2b98DEw== X-Received: by 2002:a17:902:6a8c:: with SMTP id n12mr2719851plk.124.1598021152294; Fri, 21 Aug 2020 07:45:52 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-146-144.windriver.com. [147.11.146.144]) by smtp.gmail.com with ESMTPSA id s125sm2785702pfc.63.2020.08.21.07.45.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2020 07:45:51 -0700 (PDT) From: Bin Meng To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 2/2] hw/sd: sd: Correct the maximum size of a Standard Capacity SD Memory Card Date: Fri, 21 Aug 2020 22:45:36 +0800 Message-Id: <1598021136-49525-2-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598021136-49525-1-git-send-email-bmeng.cn@gmail.com> References: <1598021136-49525-1-git-send-email-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sai Pavan Boddu , Bin Meng , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Per the SD spec, Standard Capacity SD Memory Card (SDSC) supports capacity up to and including 2 GiB. Fixes: 2d7adea4fe ("hw/sd: Support SDHC size cards") Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé Tested-by: Sai Pavan Boddu --- Changes in v3: - add Reviewed-by tag from Philippe Mathieu-Daudé - add Tested-by tag from Sai Pavan Boddu Changes in v2: - fix SDSC size check in sd_set_csd() too hw/sd/sd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3226404..254d713 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -50,6 +50,8 @@ //#define DEBUG_SD 1 +#define SDSC_MAX_CAPACITY (2 * GiB) + typedef enum { sd_r0 = 0, /* no response */ sd_r1, /* normal response command */ @@ -313,7 +315,7 @@ static void sd_ocr_powerup(void *opaque) /* card power-up OK */ sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); - if (sd->size > 1 * GiB) { + if (sd->size > SDSC_MAX_CAPACITY) { sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); } } @@ -385,7 +387,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) uint32_t sectsize = (1 << (SECTOR_SHIFT + 1)) - 1; uint32_t wpsize = (1 << (WPGROUP_SHIFT + 1)) - 1; - if (size <= 1 * GiB) { /* Standard Capacity SD */ + if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */ sd->csd[0] = 0x00; /* CSD structure */ sd->csd[1] = 0x26; /* Data read access-time-1 */ sd->csd[2] = 0x00; /* Data read access-time-2 */