From patchwork Tue Jul 9 15:25:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 811455 Delivered-To: patch@linaro.org Received: by 2002:adf:ee12:0:b0:367:895a:4699 with SMTP id y18csp346857wrn; Tue, 9 Jul 2024 08:30:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV7xMCSDoB/kPFCAcprSqCrvXf1gT0GOyPuRgvIUs2+OEXLtd50AWge11kpn3dkbGHv0PRqhrk0jezM1dZwN/Fz X-Google-Smtp-Source: AGHT+IFPIi+ptUl9l1eNEOVby6q2W55HQOn8b5NtQUzkQr4QxW1acn7qBs/koORjdPUDBiieqb7Q X-Received: by 2002:a05:620a:a58:b0:79f:90:7d50 with SMTP id af79cd13be357-79f19a80203mr287744385a.32.1720539023890; Tue, 09 Jul 2024 08:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720539023; cv=none; d=google.com; s=arc-20160816; b=e+fxCPz2dxASy3vkWeeaIILLDTJbc7v3my2K94By770L5FVpjfLi7Vv57afiK68vDj tt4x11BEG/IUb7LXWZDRyAB2NY86F/u/7mH7HcrkGveyC83z5mV4t4jNNG6pYIi93Ajr toSmQ4v/I2cKVcWZsn2wmlOgJO7D21pujcOSHjgYXPEU0wKZ3Mq7KVdcIS7SHqiyZY7Z YmRgnBQJ8HFMfnN9gbnKpaI2UXgPwXlGaP0JK+Nbz9yFsiCakF3RfUz48CgDL6RazJ+T sESQz47Rex3Ii5pKqrXDq7LQ2zFMH4dcEvBsW31mTNoscqwaFbuxk3jt+eF6JdWT4eU0 NZxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CXlLcchVuZxoQd5Ht8ddmcX5yuPtqrGnU30hdQCRZeA=; fh=Txzf7K5YV+qryaChbcvqA4D4sw+KVK3yVi4ERabJCxo=; b=XLtU6AmQ8LLciHEswgbsvsZeLLyQcp6sTrwXRdEojQvhok6GMU1cJKucYSJwZqi3Ov qm3AO87aJajVVyFTS3zuzQwOsrnD1vV2mVXqKidSjmHhmPFqU9Wa8QvxLS0wVtsAqIBP XPyM6aChLTkRYeFKOcx9kAnlH4IIrfjOPzaO+Uemi8bZs6QpNJTHU+88jEEcl3+ugHRr BNiHqMciY9cdtqg2FQoq/N5/I8rP7jLg4npZDlKy92roP+VdvdcnjGxYvs88khAllARw DrakS/v0iOqRsiXzeENZYLoFJzlgAjaLtHDG66f+ofYpFPdoqNV4hs/EjOnvjPW8IHii /MSA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLBm1JWJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79f190a18d6si231428485a.373.2024.07.09.08.30.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Jul 2024 08:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLBm1JWJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRCjs-0004Ad-2m; Tue, 09 Jul 2024 11:26:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRCjl-0003rX-AR for qemu-devel@nongnu.org; Tue, 09 Jul 2024 11:26:38 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRCji-0006Fn-BY for qemu-devel@nongnu.org; Tue, 09 Jul 2024 11:26:37 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4265c2b602aso24560175e9.3 for ; Tue, 09 Jul 2024 08:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720538792; x=1721143592; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CXlLcchVuZxoQd5Ht8ddmcX5yuPtqrGnU30hdQCRZeA=; b=wLBm1JWJAGCwpEUIz+SWZFY6BqMyJcsMhgoEZ5rmwiUhI1tgCNwQYwRQoFw9/Q/J2J Xci4BGQ7p8WlEclhjjblc1so0b1I1d8gX2n8E5Cp3makkfoeps04Ep1BoYrGRJEtM7ZY Yw3o/iSBjRdSNdigXN4Q00xOvzhrPo6RnVwO4LV5KojEnKBiAMpN8lu6k8WbonIr6XEU Wgs7RISADNilDoIyHFkUUCMzA7Nqzb6gPbn2kmYnHKpGvdaABiFUQOTEt9335jPtB0ek J87mJiMsFnCuzcOxLDSrUo+mIPoYa4Mo65wZBQPqBpStUgk0q+KsKpWFFAsnRwsEmDaP pLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720538792; x=1721143592; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CXlLcchVuZxoQd5Ht8ddmcX5yuPtqrGnU30hdQCRZeA=; b=tB+q3m6jf6Pg9M0CfejAiuVSHcw0GTEEoutlgmCVbOTWsID9tncbPBCfXZFtoXv675 zjBRQh4YMk0X+Mf7ISZInjcucraKsG+Y4bH+sw56Zyr8aPnXOsU4+IBjeKyD5x+C9gdQ BPbFDM/cAl5jxcDO2bvpBjdtf/QyAy1DsHnKrV8Sxr+YzzFxZRJVkKWK+Ic9z7q2L05F hW/YqZBnYSn2SB9S1P4HZawSJ2z5yj+VaEXIiVz60pUF7s2DxX/ucrruU8XsaaD+8NxZ ha6JrcQ/UsjxUogeB37gF62camxhmFYXWuq61dmGYtux8/wYR95aGy6vaZfHK9RhUaal tFIA== X-Gm-Message-State: AOJu0YxQLN7uNIgVe4UFbVN8A8QjfudbBSdM3wDhLRyxHWf4WJnRjWnB NTRreaQmJfSVOt6uCn8RqgT4U2REbgHugShLadtoB6jJLkllFOQqvIQMZf1DGaGMMThb1dANcc/ X X-Received: by 2002:a05:600c:534b:b0:426:6ad8:3e3c with SMTP id 5b1f17b1804b1-426707e2fa2mr19303475e9.17.1720538792517; Tue, 09 Jul 2024 08:26:32 -0700 (PDT) Received: from m1x-phil.lan (vau06-h02-176-184-43-20.dsl.sta.abo.bbox.fr. [176.184.43.20]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42662315363sm125665345e9.26.2024.07.09.08.26.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Jul 2024 08:26:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell , Andrew Jeffery , qemu-block@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Bin Meng , Joel Stanley , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Jamin Lin , Steven Lee , Troy Lee Subject: [PATCH v47 05/19] hw/sd/sdcard: Implement emmc_set_csd() Date: Tue, 9 Jul 2024 17:25:42 +0200 Message-ID: <20240709152556.52896-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240709152556.52896-1-philmd@linaro.org> References: <20240709152556.52896-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.com 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org eMMC CSD register is very similar to SD one. Most notable change: the version announced is v4.3. Signed-off-by: Philippe Mathieu-Daudé --- TODO: comment magic values? --- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2d737a836f..f580c6b2ae 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -476,6 +476,44 @@ static const uint8_t sd_csd_rw_mask[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, }; +static void emmc_set_csd(SDState *sd, uint64_t size) +{ + int hwblock_shift = HWBLOCK_SHIFT; + uint32_t sectsize = (1 << (SECTOR_SHIFT + 1)) - 1; + uint32_t wpsize = (1 << (WPGROUP_SHIFT + 1)) - 1; + + sd->csd[0] = (2 << 6) | (4 << 2); + sd->csd[1] = 0x07; + sd->csd[2] = 0x00; + sd->csd[3] = 0x32; + sd->csd[4] = 0x0f; + if (size <= 2 * GiB) { + /* use 1k blocks */ + uint32_t csize1k = (size >> (CMULT_SHIFT + 10)) - 1; + sd->csd[5] = 0x5a; + sd->csd[6] = 0x80 | ((csize1k >> 10) & 0xf); + sd->csd[7] = (csize1k >> 2) & 0xff; + } else { /* >= 2GB : size stored in ext CSD, block addressing */ + sd->csd[5] = 0x59; + sd->csd[6] = 0x8f; + sd->csd[7] = 0xff; + sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); + } + sd->csd[8] = 0xff; + sd->csd[9] = 0xfc | /* Max. write current */ + ((CMULT_SHIFT - 2) >> 1); + sd->csd[10] = 0x40 | /* Erase sector size */ + (((CMULT_SHIFT - 2) << 7) & 0x80) | (sectsize >> 1); + sd->csd[11] = 0x00 | /* Write protect group size */ + ((sectsize << 7) & 0x80) | wpsize; + sd->csd[12] = 0x90 | /* Write speed factor */ + (hwblock_shift >> 2); + sd->csd[13] = 0x20 | /* Max. write data block length */ + ((hwblock_shift << 6) & 0xc0); + sd->csd[14] = 0x00; + sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; +} + static void sd_set_csd(SDState *sd, uint64_t size) { int hwblock_shift = HWBLOCK_SHIFT; @@ -2600,6 +2638,7 @@ static void emmc_class_init(ObjectClass *klass, void *data) sc->proto = &sd_proto_emmc; sc->set_cid = emmc_set_cid; + sc->set_csd = emmc_set_csd; } static const TypeInfo sd_types[] = {