From patchwork Tue Jul 9 15:25:38 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: 811443 Delivered-To: patch@linaro.org Received: by 2002:adf:ee12:0:b0:367:895a:4699 with SMTP id y18csp345317wrn; Tue, 9 Jul 2024 08:27:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWXnqGQYrWfhe8jrKNeWVfmTAOHWGDWv33wbz8Pp5FaXNrE2vNXlUrZmd3+MRMtBty84x/6ibNr9t4SrrMxKZ8v X-Google-Smtp-Source: AGHT+IHV0B64X3xNhhd5RN6Sp6qeahfokxLvf8TZ+l+mqlAUoHVd9qRfDbb8YkGv8jIeO5x2OuH6 X-Received: by 2002:a05:6102:cca:b0:48f:92de:ddec with SMTP id ada2fe7eead31-490321a40f7mr3191075137.19.1720538821135; Tue, 09 Jul 2024 08:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720538821; cv=none; d=google.com; s=arc-20160816; b=C6S/A1WDE/NBKDXoyse+QbGp252bmpBSaUkejr4Gd6u3sft8I6KqXuE8HrtR9asXv0 3LJtoJUCa4HfSGqWsessCy7D5TFmONFGvr/bmRaGUGhTcFTxmQhXno/zw/s5f6HwwIhF +IRCU1ODkwPk4RcvSau+h5iPqPR3o8qNN7BiaE4/q3nto7H4n1Xd0mkg06SMvwaV1glx fs1xm5FbenTPDMzOzvBSlPPTRwPiepkzq4rSzygH0q7N0eHkzje1DRFvfQIiORYqkNdH xyXuel++IN47H3T/DaEFJ7aeAijRubOGc2qXDOTlQRlcPYIspvNzqu8L0qJjoOyju58B Ciow== 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=Qg1OvvbVnYB9NkPyvKNWOuJA/h7PKPgrnxpR3YQLVd8=; fh=MYHLfIjJ6Hvx7rPuopPO2Khw7ypziP9+A2jw2XPCPDM=; b=KopHyaBCb3oDu5vclPHqafZWb8QfX1oJ86gIS6yihbId47o3j5U32VWc97SGvu4Bxq UViNJXCeO34wbAOxcIJiXXwUtqvY8iIQiOBCO9kQK8q3kocV7w7489vUtiprQYpgfUmt URDHYWwQYn4ydieokbORzraclRgfod2Dh5cGx+efCvseMSVtEdZ/Cs394K4tHroDbdHD C47sXN/OJNlRjbIZfmk3WVkk6WY4mSMJ7BCOGSAu8gOx2LAyXQ4B0fcvMWDHRieaqAnw SI97uDw3e0JBREcLPPcVq4JlFn0FKnPbU/dYe5InpmUjcROiOaUIRW+QkRaGg+mpVf0m bXCQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qe79qGCD; 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 ada2fe7eead31-490317180dcsi315429137.388.2024.07.09.08.27.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Jul 2024 08:27:01 -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=qe79qGCD; 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 1sRCjQ-00030D-1t; Tue, 09 Jul 2024 11:26:16 -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 1sRCjN-0002sz-Fm for qemu-devel@nongnu.org; Tue, 09 Jul 2024 11:26:13 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRCjK-0006Bb-Iy for qemu-devel@nongnu.org; Tue, 09 Jul 2024 11:26:13 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2eea7e2b0e6so30248081fa.3 for ; Tue, 09 Jul 2024 08:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720538768; x=1721143568; 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=Qg1OvvbVnYB9NkPyvKNWOuJA/h7PKPgrnxpR3YQLVd8=; b=qe79qGCD1MrbcMPa5Gab6KXm3Nom68m4Ba/FUfPkxD7HRbaDMnBpmf71NCmQsMPoaj Em3nKRdpmg4bPTlFPRbRj80Z7OfYIHDFpHlxu612pdUb3Sw1LeV2x0KkEu5VuM/Oszim jycivY+2dXA4noodsz11gZrjS4gnMkGuORWQqzc1xORX7c/uf5gDmxiOYyqU3uX7H4Ls 3bGHS+tcrTODHJRjROmtEts6eA+lO/ZJyiGMRn5MkiKp1JFlnNR6OziIn8f9yZmECK2u ELYneF1zN0D1ZqUSlsP7BmwTFGW4UfsQ3Cnhjz5Gb4Av2vDRU6lvn0ZD20OfG3imsJ+R s91g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720538768; x=1721143568; 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=Qg1OvvbVnYB9NkPyvKNWOuJA/h7PKPgrnxpR3YQLVd8=; b=DQqTKTqnqAzI+PEcgi5jS4xnlIp3zSUO4/qLhSEeVvN1FDqXI+j+6FWl/NYDt46nCU ksT68T+t6JKnUeA7bNjMkL4AuZ5wk2dgepKKFvv0I/r4QGDCv+dtcHjnNf1Fzdy7Jslg 7Aueicf+eYeAq1ilnrSzM46zAvIKBD9KrOiwaStGolIor8oKeV9T+rQ+iXB2GWmiNQWq A+z/fNZ1VklQDQsLx1QScyA/RppMpxANTYQ4jwlF3X+X0YAa7vr94UH6UKqgT5i89vTE m/FR99dfw5DMBr15H31gyrEjIksZZEVbSHt2IcvKCrT/Jclxe28lL47y/Ed7fQlql7/H TzDw== X-Gm-Message-State: AOJu0YxcTi5W10mpTR63o4O96fp5ZYIE+TcL4kcRMQhtVivMBkJahPOd Fr/HHd3qXWD2EZntRehhs8tXJYZ6oEKC5jhw3km4it8BQFViZthYe45G+EG04je06h201ramoqk q X-Received: by 2002:a2e:3014:0:b0:2ec:543f:6013 with SMTP id 38308e7fff4ca-2eeb30d9814mr18582841fa.13.1720538766585; Tue, 09 Jul 2024 08:26:06 -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-4266f6f5f25sm46032035e9.26.2024.07.09.08.26.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Jul 2024 08:26:06 -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 , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v47 01/19] hw/sd/sdcard: Basis for eMMC support Date: Tue, 9 Jul 2024 17:25:38 +0200 Message-ID: <20240709152556.52896-2-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::233; envelope-from=philmd@linaro.org; helo=mail-lj1-x233.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 From: Philippe Mathieu-Daudé Add basis for supporting eMMC. Since eMMC are soldered on boards, it is not user-creatable. Currently TYPE_EMMC is just a stub, so disabled (marked abstract). RCA register is initialized to 1, per spec v4.3, chapter 8.5 "RCA register": The default value of the RCA register is 0x0001. The value 0x0000 is reserved to set all cards into the Stand-by State with CMD7. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- include/hw/sd/sd.h | 3 +++ hw/sd/sd.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 0d6d9e452b..d35a839f5e 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -96,6 +96,9 @@ OBJECT_DECLARE_TYPE(SDState, SDCardClass, SD_CARD) #define TYPE_SD_CARD_SPI "sd-card-spi" DECLARE_INSTANCE_CHECKER(SDState, SD_CARD_SPI, TYPE_SD_CARD_SPI) +#define TYPE_EMMC "emmc" +DECLARE_INSTANCE_CHECKER(SDState, EMMC, TYPE_EMMC) + struct SDCardClass { /*< private >*/ DeviceClass parent_class; diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d6a07f0ade..91a73aea8d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2,6 +2,8 @@ * SD Memory Card emulation as defined in the "SD Memory Card Physical * layer specification, Version 2.00." * + * eMMC emulation defined in "JEDEC Standard No. 84-A43" + * * Copyright (c) 2006 Andrzej Zaborowski * Copyright (c) 2007 CodeSourcery * Copyright (c) 2018 Philippe Mathieu-Daudé @@ -169,12 +171,18 @@ struct SDState { static void sd_realize(DeviceState *dev, Error **errp); static const SDProto sd_proto_spi; +static const SDProto sd_proto_emmc; static bool sd_is_spi(SDState *sd) { return sd->proto == &sd_proto_spi; } +static bool sd_is_emmc(SDState *sd) +{ + return sd->proto == &sd_proto_emmc; +} + static const char *sd_version_str(enum SDPhySpecificationVersion version) { static const char *sdphy_version[] = { @@ -697,7 +705,7 @@ static void sd_reset(DeviceState *dev) sd->state = sd_idle_state; /* card registers */ - sd->rca = 0x0000; + sd->rca = sd_is_emmc(sd) ? 0x0001 : 0x0000; sd->size = size; sd_set_ocr(sd); sd_set_scr(sd); @@ -2375,6 +2383,13 @@ static const SDProto sd_proto_sd = { }, }; +static const SDProto sd_proto_emmc = { + /* Only v4.3 is supported */ + .name = "eMMC", + .cmd = { + }, +}; + static void sd_instance_init(Object *obj) { SDState *sd = SDMMC_COMMON(obj); @@ -2446,6 +2461,15 @@ static void sd_realize(DeviceState *dev, Error **errp) } } +static void emmc_realize(DeviceState *dev, Error **errp) +{ + SDState *sd = SDMMC_COMMON(dev); + + sd->spec_version = SD_PHY_SPECv3_01_VERS; /* Actually v4.3 */ + + sd_realize(dev, errp); +} + static Property sdmmc_common_properties[] = { DEFINE_PROP_DRIVE("drive", SDState, blk), DEFINE_PROP_END_OF_LIST() @@ -2457,6 +2481,10 @@ static Property sd_properties[] = { DEFINE_PROP_END_OF_LIST() }; +static Property emmc_properties[] = { + DEFINE_PROP_END_OF_LIST() +}; + static void sdmmc_common_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -2509,6 +2537,20 @@ static void sd_spi_class_init(ObjectClass *klass, void *data) sc->proto = &sd_proto_spi; } +static void emmc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + SDCardClass *sc = SDMMC_COMMON_CLASS(klass); + + dc->desc = "eMMC"; + dc->realize = emmc_realize; + device_class_set_props(dc, emmc_properties); + /* Reason: Soldered on board */ + dc->user_creatable = false; + + sc->proto = &sd_proto_emmc; +} + static const TypeInfo sd_types[] = { { .name = TYPE_SDMMC_COMMON, @@ -2530,6 +2572,12 @@ static const TypeInfo sd_types[] = { .parent = TYPE_SD_CARD, .class_init = sd_spi_class_init, }, + { + .name = TYPE_EMMC, + .parent = TYPE_SDMMC_COMMON, + .class_init = emmc_class_init, + .abstract = true, /* FIXME: Remove once model fully functional */ + }, }; DEFINE_TYPES(sd_types)