From nobody Mon Nov 25 02:50:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719508454; cv=none; d=zohomail.com; s=zohoarc; b=gDaKoxX9d117xnL3qSziOGrirGrUFmunGxJkikgHpvbAL8cxnTAT459WQHVVcnUqZJqomCsSvIu9ldSBdONx83kEb9BquAQ/hTVNcCAbGl20iFTQu6pc8Oe3+afFPJW97xU2+16Ozbsxg9D9aXDnY9sCXVhX+RQsRxKdrf2iMz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719508454; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O1uKT3cac0wmROcR+mzv/OARkq5bGqfifIlHFoP/L2c=; b=OoSKEonkEIzbteBsKCA3OxldWObpMJMmp2V6hzh/j9V/XaqeLNJJk6o1Hd8dIRRbf3tDLw4dKSVu+NAGnyJmZyd/w77JIzXcZJgOIDIWNQPCtDtv5ozx/Pk+9cN+ktS8dtYB/ZFK21Q9lmUsq8v0Rn+FUg04J0JVkcUvn0k18OM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719508454444373.32717572255626; Thu, 27 Jun 2024 10:14:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMsgz-0005xD-EA; Thu, 27 Jun 2024 13:13:53 -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 1sMsgq-0005SU-Sp for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:13:48 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMsgo-0002Qz-Ph for qemu-devel@nongnu.org; Thu, 27 Jun 2024 13:13:44 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42564316479so8004905e9.2 for ; Thu, 27 Jun 2024 10:13:40 -0700 (PDT) Received: from localhost.localdomain (33.red-95-127-46.staticip.rima-tde.net. [95.127.46.33]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af55d0fsm1016565e9.19.2024.06.27.10.13.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 10:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719508419; x=1720113219; 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=O1uKT3cac0wmROcR+mzv/OARkq5bGqfifIlHFoP/L2c=; b=Xn3XC5qy7Vxn3QQFeENMEAcGDX7GkZYa2FWk9uly7Vn4q+O/JJ7K+tHcYaghMHWMAj 2U+oouZUibid+Pfo5TqM5cZL7Kq45vvz6Bz980d4I47+EwSLD/SJmoAPSvBSYPOrOh8b nRrEUiUpiKBzSemSXkwYH/hBOaudyFAfOVABUcN8+zdKG4VLpw0a9lrq0OpUlslJgQcS XobPf/TIeXP3iQSLdfxq/E2veacFXKeRkoKl1hLw7lf4NqBsWADNEngkSmffTqi5bYNZ SBs8IrdZRnbbeaAMna/jQkNJVnMdqwvQFxwedXJP83gpG30XMso/FzUI6iQhU7n9vrW7 C8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719508419; x=1720113219; 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=O1uKT3cac0wmROcR+mzv/OARkq5bGqfifIlHFoP/L2c=; b=N2WAaxcKnt5QUAKe0nRRDahOOoRlcP8B8TVKhrz5Dk8ZxjxtjVRHvbtZoCb2o9LLLh qGJgg4oPqnA9h2KkdagAGXpvLi5QHPS0faF345YoeDRyvEL9Dn+GKa50KLcgVD6ovky7 hjhlSOgo3Z2AywpS7Pp2doifNHvp5koMKWSYgeW79LlDYS2+7jv3wSUMO7r2czNlU4NE SuuOCy1c+ixDHke7lMd4/iYat+3oelEeTEHXTle+JxM5DHJaIa7igCeOMw32+Ih14Dtj tE0ZOqMWrf20kn+24mN5SKx8s6Mb8edglNGyLiXjYzptxlWC/rZxAwF7HACSVVXGwdMK rbXw== X-Gm-Message-State: AOJu0Yx7V/P7s7ueq8/K6qpGZPWl9oP0V9dlPu7X0vG5TgkZ7wjJJLVn s+p3n/44yOvhrWjVl6oUuQrO9fXmiVrqX/kYcppVSTwn4UkTkdMbK3eCyvhepxIZNvHQdOO0gND 9oXM= X-Google-Smtp-Source: AGHT+IGq36AEzflYez2c0YMFH6Y8h+wBmBzgVy6cBDvUdRpjMLwIfFt0l0+W1g3MBWJLkwMsAUqTNA== X-Received: by 2002:a05:600c:993:b0:424:a5d6:6512 with SMTP id 5b1f17b1804b1-424a5d665f9mr52903405e9.20.1719508418077; Thu, 27 Jun 2024 10:13:38 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Joel Stanley , Luc Michel , Francisco Iglesias , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vincent Palatin , Sai Pavan Boddu , Bin Meng , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Sai Pavan Boddu , "Edgar E . Iglesias" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [RFC PATCH 14/19] hw/sd/sdcard: Add emmc_cmd_SEND_EXT_CSD handler (CMD8) Date: Thu, 27 Jun 2024 19:10:54 +0200 Message-ID: <20240627171059.84349-15-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627171059.84349-1-philmd@linaro.org> References: <20240627171059.84349-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719508456189100003 From: Vincent Palatin The parameters mimick a real 4GB eMMC, but it can be set to various sizes. Initially from Vincent Palatin eMMC CSD is similar to SD with an option to refer EXT_CSD for larger devices. Signed-off-by: Vincent Palatin Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- TODO simplify params, see: https://lore.kernel.org/qemu-devel/54bc25fd-acea-44a3-b696-c261e7e9706d@kao= d.org/ --- hw/sd/sd.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 82e0b5838f..0561079eff 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -122,6 +122,7 @@ struct SDState { uint16_t rca; uint32_t card_status; uint8_t sd_status[64]; + uint8_t ext_csd[512]; =20 /* Static properties */ =20 @@ -460,6 +461,82 @@ static const uint8_t sd_csd_rw_mask[16] =3D { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, }; =20 +static void mmc_set_ext_csd(SDState *sd, uint64_t size) +{ + uint32_t sectcount =3D size >> HWBLOCK_SHIFT; + + memset(sd->ext_csd, 0, sizeof(sd->ext_csd)); + + sd->ext_csd[EXT_CSD_S_CMD_SET] =3D 0x1; /* supported command sets */ + sd->ext_csd[EXT_CSD_HPI_FEATURES] =3D 0x3; /* HPI features */ + sd->ext_csd[EXT_CSD_BKOPS_SUPPORT] =3D 0x1; /* Background operations */ + sd->ext_csd[241] =3D 0xA; /* 1st initialization time after partitionin= g */ + sd->ext_csd[EXT_CSD_TRIM_MULT] =3D 0x1; /* Trim multiplier */ + sd->ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] =3D 0x15; /* Secure feature */ + sd->ext_csd[EXT_CSD_SEC_ERASE_MULT] =3D 0x96; /* Secure erase support = */ + sd->ext_csd[EXT_CSD_SEC_TRIM_MULT] =3D 0x96; /* Secure TRIM multiplier= */ + sd->ext_csd[EXT_CSD_BOOT_INFO] =3D 0x7; /* Boot information */ + sd->ext_csd[EXT_CSD_BOOT_MULT] =3D 0x8; /* Boot partition size. 128KB = unit */ + sd->ext_csd[EXT_CSD_ACC_SIZE] =3D 0x6; /* Access size */ + sd->ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] =3D 0x4; /* HC Erase unit size = */ + sd->ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] =3D 0x1; /* HC erase timeout */ + sd->ext_csd[EXT_CSD_REL_WR_SEC_C] =3D 0x1; /* Reliable write sector co= unt */ + sd->ext_csd[EXT_CSD_HC_WP_GRP_SIZE] =3D 0x4; /* HC write protect group= size */ + sd->ext_csd[EXT_CSD_S_C_VCC] =3D 0x8; /* Sleep current VCC */ + sd->ext_csd[EXT_CSD_S_C_VCCQ] =3D 0x7; /* Sleep current VCCQ */ + sd->ext_csd[EXT_CSD_S_A_TIMEOUT] =3D 0x11; /* Sleep/Awake timeout */ + sd->ext_csd[215] =3D (sectcount >> 24) & 0xff; /* Sector count */ + sd->ext_csd[214] =3D (sectcount >> 16) & 0xff; /* ... */ + sd->ext_csd[213] =3D (sectcount >> 8) & 0xff; /* ... */ + sd->ext_csd[EXT_CSD_SEC_CNT] =3D (sectcount & 0xff); /* ... */ + sd->ext_csd[210] =3D 0xa; /* Min write perf for 8bit@52Mhz */ + sd->ext_csd[209] =3D 0xa; /* Min read perf for 8bit@52Mhz */ + sd->ext_csd[208] =3D 0xa; /* Min write perf for 4bit@52Mhz */ + sd->ext_csd[207] =3D 0xa; /* Min read perf for 4bit@52Mhz */ + sd->ext_csd[206] =3D 0xa; /* Min write perf for 4bit@26Mhz */ + sd->ext_csd[205] =3D 0xa; /* Min read perf for 4bit@26Mhz */ + sd->ext_csd[EXT_CSD_PART_SWITCH_TIME] =3D 0x1; + sd->ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] =3D 0x1; + sd->ext_csd[EXT_CSD_CARD_TYPE] =3D 0x7; + sd->ext_csd[EXT_CSD_STRUCTURE] =3D 0x2; + sd->ext_csd[EXT_CSD_REV] =3D 0x5; + sd->ext_csd[EXT_CSD_RPMB_MULT] =3D 0x1; /* RPMB size */ + sd->ext_csd[EXT_CSD_PARTITION_SUPPORT] =3D 0x3; + sd->ext_csd[159] =3D 0x00; /* Max enhanced area size */ + sd->ext_csd[158] =3D 0x00; /* ... */ + sd->ext_csd[157] =3D 0xEC; /* ... */ +} + +static void sd_emmc_set_csd(SDState *sd, uint64_t size) +{ + sd->csd[0] =3D 0xd0; + sd->csd[1] =3D 0x0f; + sd->csd[2] =3D 0x00; + sd->csd[3] =3D 0x32; + sd->csd[4] =3D 0x0f; + if (size <=3D 2 * GiB) { + /* use 1k blocks */ + uint32_t csize1k =3D (size >> (CMULT_SHIFT + 10)) - 1; + sd->csd[5] =3D 0x5a; + sd->csd[6] =3D 0x80 | ((csize1k >> 10) & 0xf); + sd->csd[7] =3D (csize1k >> 2) & 0xff; + } else { /* >=3D 2GB : size stored in ext CSD, block addressing */ + sd->csd[5] =3D 0x59; + sd->csd[6] =3D 0x8f; + sd->csd[7] =3D 0xff; + sd->ocr =3D FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); + } + sd->csd[8] =3D 0xff; + sd->csd[9] =3D 0xff; + sd->csd[10] =3D 0xf7; + sd->csd[11] =3D 0xfe; + sd->csd[12] =3D 0x49; + sd->csd[13] =3D 0x10; + sd->csd[14] =3D 0x00; + sd->csd[15] =3D (sd_crc7(sd->csd, 15) << 1) | 1; + mmc_set_ext_csd(sd, size); +} + static void sd_set_csd(SDState *sd, uint64_t size) { int hwblock_shift =3D HWBLOCK_SHIFT; @@ -1364,6 +1441,17 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd= , SDRequest req) return sd_r7; } =20 +/* CMD8 */ +static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) +{ + if (sd->state !=3D sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), + sd->ext_csd, sizeof(sd->ext_csd)); +} + /* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) { @@ -2297,6 +2385,7 @@ uint8_t sd_read_byte(SDState *sd) sd->data_offset, sd->data_size, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ + case 8: /* CMD8: SEND_EXT_CSD */ case 9: /* CMD9: SEND_CSD */ case 10: /* CMD10: SEND_CID */ case 13: /* ACMD13: SD_STATUS */ @@ -2474,6 +2563,7 @@ static const SDProto sd_proto_emmc =3D { [4] =3D {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] =3D {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, [7] =3D {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [8] =3D {0, sd_adtc, "SEND_EXT_CSD", emmc_cmd_SEND_EXT_CSD}, [9] =3D {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] =3D {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [12] =3D {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSI= ON}, @@ -2649,6 +2739,7 @@ static void emmc_class_init(ObjectClass *klass, void = *data) dc->desc =3D "eMMC"; dc->realize =3D emmc_realize; sc->proto =3D &sd_proto_emmc; + sc->set_csd =3D sd_emmc_set_csd; } =20 static const TypeInfo sd_types[] =3D { --=20 2.41.0