From patchwork Wed Jul 10 14:13:57 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: 1958862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UQAz8XMI; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0HM5Kcbz20MK for ; Thu, 11 Jul 2024 00:14:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY5S-0005O6-Ts; Wed, 10 Jul 2024 10:14:27 -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 1sRY5R-0005Ey-8U for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:25 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5O-0003oQ-Te for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:24 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-36796d2e5a9so4248276f8f.3 for ; Wed, 10 Jul 2024 07:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620859; x=1721225659; 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=7+n7iA8FGhZGBefoarGDOiJy21w0ojlipWHKW8I5p4Y=; b=UQAz8XMIw/1TEXi0nbXIajjc4pCT7cAglQV8h/v1N7xyWFAYcSQQT7jlMlL+cRhlJp Wy9mDzca748iC6M7V7FHZSHDI3YJY2yyowkYqyR9p+Io5Esfam5+RaEKqXEdsg3Rhi2k TRCUC6CNIrhEaIBi3i3B9yjbStViFFCKa1YdH+onPZyEob635Tzoqf3pqmqqe1XK7Af6 fM7slkUAafWk192TqZS/6jtkVrAydn6/TXeqxicD+1RtF2F8iFBUPspNxz3amit1H53q B9+7oBc/+MA3uA8/qntwrkxO1OwmGYYYDHjoYJS+Im6Fx0ZxO1UhQgsQ6N9YnGiwUd+J cN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620859; x=1721225659; 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=7+n7iA8FGhZGBefoarGDOiJy21w0ojlipWHKW8I5p4Y=; b=j+ZF8qIS82aK4xdDg7j7isOxRTK6bVmz1yc+rmRRy13SmO5ftiZpu5RZQlc8q60+W8 JpJUQ5mDruS8Z9163h/Ygyctbsdrws69EhUJbPQbeb5h66mofxk/leEH1Y2tSIPEd/Ov drT2RYjVxw6gaX8fEuPKypT28QwUuTv5JqYaPtUtkFS1EFueiT6GK9NuXI2/eCG1sVtf rMoHFjF3PaIFX0kX845e9AWxRmURdRDwX6h5ZJdGnQIpEHg7ofWFwltgJF+XLxE5NjmL H6EPIHWw8IlHCGLumyeP+MsmnGOkB+pVRYuEKbRBPN4Nx237zVSTH3WWXL9z5MQggOvM mp0A== X-Gm-Message-State: AOJu0YxInKa8dFZBFOJnpqo3/5kcP5jVA2XVSWePimtx+/rFpSYtaK9a cL2KiDHnd/bkULMVXQwfqvV0/fOAhRXJ4lYnO85LzQ9a1mmUSkXV7gNcQisulMUb2Igv1raiR+A L X-Google-Smtp-Source: AGHT+IHEmKsViy5gW8ZJF7bb5wzXJ8yTMMi98BAp7u1fQE1m221IcePuXQaYRF5zqE8sSRKGq2PDIw== X-Received: by 2002:a5d:4e46:0:b0:367:9522:5e70 with SMTP id ffacd0b85a97d-367ceacb5c0mr4075492f8f.52.1720620859363; Wed, 10 Jul 2024 07:14:19 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfab16csm5390472f8f.93.2024.07.10.07.14.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:18 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v48 01/12] hw/sd/sdcard: Basis for eMMC support Date: Wed, 10 Jul 2024 16:13:57 +0200 Message-ID: <20240710141408.69275-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=philmd@linaro.org; helo=mail-wr1-x429.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Philippe Mathieu-Daudé Since eMMC are soldered on boards, it is not user-creatable. RCA register is initialized to 0x0001, 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. The CSD register is very similar to SD one, except the version announced is v4.3. eMMC CID register is slightly different from SD: - One extra PNM (5 -> 6) - MDT is only 1 byte (2 -> 1). Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- TODO: comment magic CSD values? --- include/hw/sd/sd.h | 3 ++ hw/sd/sd.c | 107 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 109 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..a4b6c7baba 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[] = { @@ -438,6 +446,23 @@ static void sd_set_cid(SDState *sd) sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1; } +static void emmc_set_cid(SDState *sd) +{ + sd->cid[0] = MID; /* Fake card manufacturer ID (MID) */ + sd->cid[1] = 0b01; /* CBX: soldered BGA */ + sd->cid[2] = OID[0]; /* OEM/Application ID (OID) */ + sd->cid[3] = PNM[0]; /* Fake product name (PNM) */ + sd->cid[4] = PNM[1]; + sd->cid[5] = PNM[2]; + sd->cid[6] = PNM[3]; + sd->cid[7] = PNM[4]; + sd->cid[8] = PNM[4]; + sd->cid[9] = PRV; /* Fake product revision (PRV) */ + stl_be_p(&sd->cid[10], 0xdeadbeef); /* Fake serial number (PSN) */ + sd->cid[14] = (MDT_MON << 4) | (MDT_YR - 1997); /* Manufacture date (MDT) */ + sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1; +} + /* Card-Specific Data register */ #define HWBLOCK_SHIFT 9 /* 512 bytes */ @@ -451,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; @@ -697,7 +760,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 +2438,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 +2516,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 +2536,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 +2592,23 @@ 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; + + sc->set_cid = emmc_set_cid; + sc->set_csd = emmc_set_csd; +} + static const TypeInfo sd_types[] = { { .name = TYPE_SDMMC_COMMON, @@ -2530,6 +2630,11 @@ 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, + }, }; DEFINE_TYPES(sd_types) From patchwork Wed Jul 10 14:13:58 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: 1958864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=sZPa7TqL; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0Jc26Wfz1xpd for ; Thu, 11 Jul 2024 00:16:00 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY5X-0005ux-Tz; Wed, 10 Jul 2024 10:14:31 -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 1sRY5W-0005im-0n for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:30 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5T-0003pV-Ne for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:29 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2ebe40673d8so85008341fa.3 for ; Wed, 10 Jul 2024 07:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620865; x=1721225665; 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=5A72BhSEgW2r7oVyXyiETrkNoXhVnGhowikXNWfzjCw=; b=sZPa7TqLzfYK8tHyPob2zJulumiKbUdkhSpFSYu072oVeQCRab3MLQtu84IQGPnHto UQzUms4VXAS4TrUbp0/j0phyRS5zulOAhQ/Mtu07t7Ot16Ap9UkM6Mqwt+rm+23X530V AOZ/ebzw0OZBNkSpR1LGIwECksqazE0YcWz8I7Y2tpr2ni2T2JjfTUAbpOGbebh92XTZ tKJwolzLl7XXAdpub0/r54OZQ24OaWtYQKr0Qq/NPl5GVC76fGaOF6bnjokKl8/WMudM fz8roZRIVVPc8KBUMT4IglfcCBeTaxvrZ4VdJooZU1s4GQi/TyCCflfySNZffX4Hz9GP TDaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620865; x=1721225665; 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=5A72BhSEgW2r7oVyXyiETrkNoXhVnGhowikXNWfzjCw=; b=grgqSDjGtABRoZBE6GAwCPVMOxZyowvBan2Eo4DGDhXhIV4CRQl6a3gUNinL6W3OWV ouHJglBLHrgGNOERMkeJDhNDce2tkCFqCQwR5F0wy4w3GQEjqOxrhY/HGLzWNYwlyrj3 XrohoY0X/gNYCnuSVpoC9Me5rOVgodcY37yKXM/0heIWcdpfcvwUkK5Y04O8mn9nac+e yVqsZmtVYdHaQUgCwJjxDkq327ik5v9w15M9hB7hNo+lTq24YbCcLu7anvw1uhqAcgxr iN1bg0Pd9/vXKOdgCehZZuo8z/UrLZE+84lyHeqdLeSOq2P3wp1o8Up0uFQfEjfoR4/+ +AoQ== X-Gm-Message-State: AOJu0YxtVrD4X1HgogCKjn5BtIYnCVWKvXvNTDfGPbmYjmK2whydv+vZ DDhWlEdReInShQf2uvOgKAJYZ0p2deUJxAmnJuQNwXrUcT3H8QdbaYsLUrGzAbK2TIycN5Useal I X-Google-Smtp-Source: AGHT+IFSJ7le+J66OuctsqK0pvTRJajKeWsYal7fWEjH7wvZPN+i9HtR1CWv/17W5OyLQxz62gWppw== X-Received: by 2002:a2e:8297:0:b0:2ec:6639:120a with SMTP id 38308e7fff4ca-2eeb30bbb0fmr39555241fa.10.1720620865522; Wed, 10 Jul 2024 07:14:25 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde84707sm5367623f8f.35.2024.07.10.07.14.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v48 02/12] hw/sd/sdcard: Register generic command handlers Date: Wed, 10 Jul 2024 16:13:58 +0200 Message-ID: <20240710141408.69275-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=philmd@linaro.org; helo=mail-lj1-x234.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=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Tested-by: Andrew Jeffery Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a4b6c7baba..fc78d4e561 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2442,6 +2442,29 @@ static const SDProto sd_proto_emmc = { /* Only v4.3 is supported */ .name = "eMMC", .cmd = { + [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] = {0, sd_bcr, "SEND_OP_COND", sd_cmd_SEND_OP_COND}, + [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, + [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, + [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, + [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_adtc, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [35] = {5, sd_ac, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [36] = {5, sd_ac, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, + [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_adtc, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, + [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, + [56] = {8, sd_adtc, "GEN_CMD", sd_cmd_GEN_CMD}, }, }; From patchwork Wed Jul 10 14:13:59 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: 1958861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZY7dKOF6; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0HM5npTz20MN for ; Thu, 11 Jul 2024 00:14:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY5c-0006G1-GU; Wed, 10 Jul 2024 10:14:36 -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 1sRY5b-0006D8-Pq for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:35 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5Z-0003tD-Fr for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:35 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4266ea6a412so19081485e9.1 for ; Wed, 10 Jul 2024 07:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620872; x=1721225672; 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=3I/yTIseLTK5bt0dkyKiRUKUXbkR7H64cwH+I5yJrCY=; b=ZY7dKOF6Hk6YQfYEtJPlbBYCd9BJ2vtPUydxRrm7MGC0JuXjp4OodqjCV0Tnp7oL0m RwakwA1GHTeCL2bZ7qUnnRwuy7JNRLOjH/Koc3slugICYN8kXDwqgBtUE71P02ACNWao OsmxAPo9XfEqliXMR42rcfDyolXKQmAgNe+qRYUstU5Nu5OsT1wR5w8GyK+eE5f4XTNz HJCs6a8jcf3jA/pNBPASmEMpzn8M54QtApps9eI19xMcCbMc7hrY4G3UpXftz039YZk7 /z/vS1A3l+ClACrsKGMRpEX7VNVA2kq5SEWl+ySDTocBdMpkqgY+VRE1mQm2mvRLS0Fm ZkBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620872; x=1721225672; 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=3I/yTIseLTK5bt0dkyKiRUKUXbkR7H64cwH+I5yJrCY=; b=eopX7UuQSfEGzxV325IUYiaMLcjMPUJ3NpeTjqPpuPfJImBMlS9OSW99eB2AaYNoUe Je/eN8PBvXBgQAT17Hr+9kXWslEO9XhxDKmapz0CLf9Zsa/02lo1E6VoV6JBVMuYX10m txJ381NOKOLXSSIIzji0qimjDvy0O3DjQhPrg8V89yS9wYluvyuh2JZdy+aRpuoSleZq FzighraqzGgzqdJws/5akpyaTv65aYh5iI02uiIZXAJAJkDfQ/ASidR0Hmmdee3hJpe8 FxshGivfEcn3UVw72lcu2CHqRMp/y+9fVEwgh0VnXidr9pDnUtBJiNeQUFIMR8vZLR/V chaA== X-Gm-Message-State: AOJu0Yxnt2gja5vBTB2l8J7/zl1eQ3wCbgpiSy6wbaTu1P1IhwEEJ9le D6T1T5B1iZtgURU6cQGypP+b6f9jOC9coEVTazshYMMRXmQ2l6K/DiVpnFMBN6kl0uL5XT6L6iW 9 X-Google-Smtp-Source: AGHT+IG+lUZBbSVHdGO0jy1gox7O6Be1AM76DGFVl4UVCceHiNcLV3OGqPdJ1m83AXvoMKvjkYfJAw== X-Received: by 2002:a05:600c:17d5:b0:426:5fbc:f319 with SMTP id 5b1f17b1804b1-426708f04b8mr36225415e9.33.1720620871819; Wed, 10 Jul 2024 07:14:31 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266f6f5a32sm83616825e9.24.2024.07.10.07.14.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v48 03/12] hw/sd/sdcard: Register unimplemented command handlers Date: Wed, 10 Jul 2024 16:13:59 +0200 Message-ID: <20240710141408.69275-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Per the spec v4.3 these commands are mandatory, but we don't implement them. Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Tested-by: Andrew Jeffery Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fc78d4e561..0e36b0cc2e 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2445,24 +2445,33 @@ static const SDProto sd_proto_emmc = { [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_bcr, "SEND_OP_COND", sd_cmd_SEND_OP_COND}, [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, + [11] = {1, sd_adtc, "READ_DAT_UNTIL_STOP", sd_cmd_unimplemented}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [14] = {0, sd_adtc, "BUSTEST_R", sd_cmd_unimplemented}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_adtc, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [19] = {0, sd_adtc, "BUSTEST_W", sd_cmd_unimplemented}, + [20] = {3, sd_adtc, "WRITE_DAT_UNTIL_STOP", sd_cmd_unimplemented}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [31] = {6, sd_adtc, "SEND_WRITE_PROT_TYPE", sd_cmd_unimplemented}, [35] = {5, sd_ac, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, [36] = {5, sd_ac, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, + [39] = {9, sd_ac, "FAST_IO", sd_cmd_unimplemented}, + [40] = {9, sd_bcr, "GO_IRQ_STATE", sd_cmd_unimplemented}, [42] = {7, sd_adtc, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, + [49] = {0, sd_adtc, "SET_TIME", sd_cmd_unimplemented}, [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, [56] = {8, sd_adtc, "GEN_CMD", sd_cmd_GEN_CMD}, }, From patchwork Wed Jul 10 14:14:00 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: 1958866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Wl/4rzTW; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0Jc3jJgz20MN for ; Thu, 11 Jul 2024 00:16:00 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY5j-0006lF-IW; Wed, 10 Jul 2024 10:14:43 -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 1sRY5h-0006ep-Uq for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:41 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5f-0003wL-LM for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:41 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3678aa359b7so582882f8f.1 for ; Wed, 10 Jul 2024 07:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620878; x=1721225678; 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=ZV038v5PDie+4o0LGXftDcMbGJXn076Mf/fA/l7/zi4=; b=Wl/4rzTWaMn0m3bUk3wQobzZlWQuPNzhM54J766v65EdsBhE1CZyq4+jRR1G/O5Vxy OQLmAR2D9oS+eXg8qYZRxwsLQSC9q4JJafwTXl3Ri9GVn/eiqgtoXZoWaZAVf4omBCBz QLP4QFvVQHe8P1k58/bkaLGNtz2ZF7qEIeITaTQNQeSjXDZXAoAG0g1ce2O0Ekol8q3X 52wm2PWRL9p8vn2DWKM1AJU/sjzf6pCUmWs/7TdwPUBx3nzB2twpZcQ5kBwUyJG4Y7pa JYajJc7YiBYi5J+jYJzfeH8E2Hv5T8yemBzzZsSf+tl/mniwXFQjSZ2+TnteOy4KPByC b4Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620878; x=1721225678; 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=ZV038v5PDie+4o0LGXftDcMbGJXn076Mf/fA/l7/zi4=; b=BNCe93dJSfAcu+FQ3V6XXDeOqGBuFQtayeKu2AWxgDpB5o/s4sVC5J8g2EZbZrIkK/ 31ByURMrBt2bKgarkFtDxoCK8yfcMGacSNR66zK0wPKcIBSW7MCuZiW4b0fITLCoEuIl yNSpyuHzB8xzX1GRqOY6Ucg/BdSe4sydMOrcqL14NHfCZtoDJp3OiLrqFvtolCaQULKp VUuUiGJo6BaIb9p/hdfM9lVxYEGLKji3sBhJeWEgIBZ6Ip71OqbIKFRGM/PrpyeJI8ii S/Lf8YuweZFhdaQVOWP61F5/kZs0rkoVaxHn1dmu5EcLrl9sGjF7jjDFNV2/Nl1rx1DU 0cqA== X-Gm-Message-State: AOJu0YzeW1x5HEbFQxAxOd5mWorSh1spYMZRLlfCM/yyi2pO2pDV2w7j qDqsNFPjmUYM6IDM6lSBGAhF84Oj6PTk29vZ59K7DDKNrKgWvqjRmURD9O9kOLjMg/BVrWqAY5Y d X-Google-Smtp-Source: AGHT+IHhoF0ZPX5AQZ7k/KEXpbpqEQGMlfXRzYVGBIhc3MsQccrq5UXAl/qWfEfM57gSpqpNo1RY7g== X-Received: by 2002:a5d:4387:0:b0:367:8fe2:7d8b with SMTP id ffacd0b85a97d-367d2e78dfemr4492467f8f.31.1720620877886; Wed, 10 Jul 2024 07:14:37 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfab1cbsm5493344f8f.100.2024.07.10.07.14.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 04/12] hw/sd/sdcard: Add emmc_cmd_SET_RELATIVE_ADDR handler (CMD3) Date: Wed, 10 Jul 2024 16:14:00 +0200 Message-ID: <20240710141408.69275-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=philmd@linaro.org; helo=mail-wr1-x436.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Cédric Le Goater Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater Tested-by: Andrew Jeffery Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0e36b0cc2e..7e17bd0736 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1280,6 +1280,20 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +static sd_rsp_type_t emmc_cmd_SET_RELATIVE_ADDR(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_identification_state: + case sd_standby_state: + sd->state = sd_standby_state; + sd_set_rca(sd, req.arg >> 16); + return sd_r1; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD6 */ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) { @@ -2445,6 +2459,7 @@ static const SDProto sd_proto_emmc = { [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_bcr, "SEND_OP_COND", sd_cmd_SEND_OP_COND}, [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] = {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, From patchwork Wed Jul 10 14:14:01 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: 1958863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=gg75dxbE; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0HQ51vzz1xqc for ; Thu, 11 Jul 2024 00:14:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY5p-0007ED-BJ; Wed, 10 Jul 2024 10:14:49 -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 1sRY5o-00076O-7B for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:48 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5m-0003xN-Mc for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:47 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4266182a9d7so26127165e9.0 for ; Wed, 10 Jul 2024 07:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620884; x=1721225684; 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=dSXWTIJRY6bXt8qFvPRs+ninmnXE9NGGsYv1EsJJ090=; b=gg75dxbEbAUxE08kNdqfuHAsFsznd9xgDtM8xCLYuMTn6g/CmRNWV3PZVeapWmPwn7 hQr7MNOZVfT8DljvQQru1ud4/pK7SKNbGQpOVWeH7yGnZxLdu7/KbfBzbBd6SnKjJzVA 7UwMatmtKAgzYuJu2K/fjs5b3gq6UuOOUllp31EoRJrKllDmLk0hHDbwfdcTqtxhCfW8 HFwFz69ZWQZW5bn3pO1CMOnFJSZJBg0YJoOC/0GwU4NoJlSmX3NgqyZclD4lCEj0xmKq OyFyhibdfxY3EPvswP9YwoScm3KIyDvGQsK2uHtk4vDCf3YqxDzuIh/hIsMy9OpEZz7t /N5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620884; x=1721225684; 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=dSXWTIJRY6bXt8qFvPRs+ninmnXE9NGGsYv1EsJJ090=; b=YxLCDDxtbQwoZ+fjDBxpyfR8O5vOsjIHi0hh0vU6+UlBlDJcbw+B15ccCmLSnGVNcV JtPSVANwFRgKBe7DKsHgW0lUn1D7i+QV+k/LN1k42u4pfWB/41jRM8mNXuoQkDfu4Mw0 P9ioKTPsJQ3f5i/Gsz1hUOOodb9/DcxsinDIylmtuSpyMjcZeO1olg/bMxKP39whZLpr 6qoZieRAOqZsJ+DFJESQqwWlLrp+fDsfom7QOVStlFX+tL2R22jewdb7xpH+gjHkESLz qUDExoHze2SiSofKqYhodvU3OEcsl+Ogm4LcktxD/BUbH3xgh9Fz0m/zaEda2upDMN7W Q+Sg== X-Gm-Message-State: AOJu0YwI3akLcf2MOKIzE7HVIrA9rgLQFWU4Od50SjVZQxlaNzcAb+Dt PSTIIKgRdCQeyxl2HIVTQEWPq5OWhmqD86uez0zVkvxKGrzh/PdRd91KxB6zzpyunuPpbPBWrV2 O X-Google-Smtp-Source: AGHT+IGX3xXksQ4UBvTzvTYutdKY8VilzJjCXFMX/PxCZUcu3yG0NM0qRe3yubJ3QY2H/Gmr0SHuPw== X-Received: by 2002:a05:600c:245:b0:426:6099:6eaa with SMTP id 5b1f17b1804b1-426708f2020mr34787305e9.26.1720620883921; Wed, 10 Jul 2024 07:14:43 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42726c62ed2sm52106205e9.15.2024.07.10.07.14.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 05/12] hw/sd/sdcard: Fix SET_BLOCK_COUNT command argument on eMMC (CMD23) Date: Wed, 10 Jul 2024 16:14:01 +0200 Message-ID: <20240710141408.69275-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Cédric Le Goater The number of blocks is defined in the lower bits [15:0]. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater Tested-by: Andrew Jeffery Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7e17bd0736..550f63418e 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1533,6 +1533,9 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) } sd->multi_blk_cnt = req.arg; + if (sd_is_emmc(sd)) { + sd->multi_blk_cnt &= 0xffff; + } trace_sdcard_set_block_count(sd->multi_blk_cnt); return sd_r1; From patchwork Wed Jul 10 14:14:02 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: 1958867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=rlWJczvM; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0Js5PF9z1xpd for ; Thu, 11 Jul 2024 00:16:13 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY6r-0002PV-KV; Wed, 10 Jul 2024 10:15:54 -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 1sRY5v-0007qj-Rb for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:01 -0400 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY5s-0003yN-2k for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:14:55 -0400 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2ec61eeed8eso76269661fa.0 for ; Wed, 10 Jul 2024 07:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620890; x=1721225690; 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=5jntY4rbxkV0U31BLAJxtgRo8uMbZXfthoHz8ocRbQY=; b=rlWJczvMR9GC/fTqiQ+YzhLt9cpc4IelvTWnhR7MLdKfPofmg69Go6CEk1F1tPlaCZ +iMOXrYXb2DFVqtyQN8c8t1BNDzpaIofLEtNoPBsO6aeg0kx9wEQ9chD1DiOPUOlBL1Q 5x2eHk7LfWyUy1bNTfWBA1jXoUTgzASeKPqZzbLGprliZcjzodMMou6iev1nzamm7CgZ Ao5UZozjyJ5kLBfbThuHXrMGburue0QWlOV7pRYLM4UWBwlAp2wR3kAMK0OZRfOfFwv9 wBSQ5hpqkd22S8kmiL4t5eNqEfRfqJT1a+sys3HrvO6tgD13z/8a2RX21p0drolVjJA0 /wPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620890; x=1721225690; 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=5jntY4rbxkV0U31BLAJxtgRo8uMbZXfthoHz8ocRbQY=; b=izfsqSvmvjc8l4VofBeOBARsnsmWf+XQP1BUHUyemmwR6NOB5m2RkXOcGst53Oip0j oS8JpSdS1caDKEulqyOPbOWXK1gjR2B5bzMTWVQOttZU7P85C+osHpMmdRTnVfrKj53V pjqb2fXr0ypUPM3uGrc2/GVojix9sZ6iwgiQ2Z0EwNhp7cuLhKAElwk2RSPYc6E6o+2t 2PXx8Vm1LvmJfH86kjAvsFczsTw1Gu944zn7fmiYcc07AnS3P1Mwbitcf7B2GsESQP2B hmhILA5hovUE0azJggaBofE8zSCdWZ0g0HaZPJDtuICswwjdLFDyAwoFtrrXJkChtoG3 CR4w== X-Gm-Message-State: AOJu0YyPspGcYUR2Zw8X60O66cp63Z5qUcz2sJcuojsGoBt9E9HQwJt4 WG+nUURkkNRcOFwIIfUSftY4br/VLIT7huLM42BoJOy9ZQ8plhQcMsBy3KHqkDAEIhdrpBOxGpS n X-Google-Smtp-Source: AGHT+IEeo8IzPPhd9ZX/skDWQnPjvz44PmtNZSuFjkEdruohVeAi7cjGlcWI3h1SgWquMUkLtucGsA== X-Received: by 2002:a2e:9c8f:0:b0:2ee:bd1b:84c with SMTP id 38308e7fff4ca-2eebd1b173cmr20288141fa.0.1720620890154; Wed, 10 Jul 2024 07:14:50 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427165c69f0sm60227135e9.30.2024.07.10.07.14.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v48 06/12] hw/sd/sdcard: Add mmc_cmd_PROGRAM_CID handler (CMD26) Date: Wed, 10 Jul 2024 16:14:02 +0200 Message-ID: <20240710141408.69275-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22b; envelope-from=philmd@linaro.org; helo=mail-lj1-x22b.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Tested-by: Andrew Jeffery --- hw/sd/sd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 550f63418e..3628686832 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1568,6 +1568,12 @@ static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); } +/* CMD26 */ +static sd_rsp_type_t mmc_cmd_PROGRAM_CID(SDState *sd, SDRequest req) +{ + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); +} + /* CMD27 */ static sd_rsp_type_t sd_cmd_PROGRAM_CSD(SDState *sd, SDRequest req) { @@ -1917,9 +1923,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 26: /* CMD26: PROGRAM_CID */ - return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); - default: qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); return sd_illegal; @@ -2478,6 +2481,7 @@ static const SDProto sd_proto_emmc = { [20] = {3, sd_adtc, "WRITE_DAT_UNTIL_STOP", sd_cmd_unimplemented}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [26] = {4, sd_adtc, "PROGRAM_CID", mmc_cmd_PROGRAM_CID}, [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, From patchwork Wed Jul 10 14:14:03 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: 1958868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ITtBZ9IL; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0Jt1qkjz20MK for ; Thu, 11 Jul 2024 00:16:14 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY71-0003ys-Qb; Wed, 10 Jul 2024 10:16:04 -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 1sRY62-0008Il-Td for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:07 -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 1sRY5z-0003zW-IJ for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:01 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2eebc76119aso15808781fa.2 for ; Wed, 10 Jul 2024 07:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620896; x=1721225696; 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=MdllFDvAAAapWc9IpfzuQduI83NS5VUSC4hX+cxnlVQ=; b=ITtBZ9IL/y7oWbbPMgltYBk+YJ1xs0mclnl70ur1403UXjtrHUx/E+uRe/LhVZkhf8 tkteQ+9Ycd8fX91Qc737yrksnrBUJrOk6cpb2Ks/YBjwWThCoOqjy1jib6oP8elXXQj4 36d10M+AwO0znbTxqOQPbpVlqKzSfcHAANUE8CFtmt4sLVzo2k3ICUb2pnFQRw0R5OFw nDNOvKCcQ2APBYRlGpa/zTYAFqcLQEZVrNGPPzlXCJS3Q74ek9MP85/QR/+QQgcHnfEd CKGfJCW5x0J2i2UPiiyLkXJ3EVN8YQOv/KGuYv0ERyAmHsyygWDv6WV3SM/Tplo/mHoR sC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620896; x=1721225696; 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=MdllFDvAAAapWc9IpfzuQduI83NS5VUSC4hX+cxnlVQ=; b=iT4tepzz6KdtYGHzakVybXlYcWno3SHGHE5g3EnmcXufI/ffqP3QSruPglnpJ2EOzT mxdFavcXnJPo+TL6U9yY7BMWCp1CD0Je+7jOZIjF19atldLquJz8nT4AqbUjEuDS5p/d omg6mvXhSdO4/ZAP/LmtPlQSIkdSrMYelPJI4hqA7DkXZGIVJIHH9+vRlv59tdZK14Qa p9GPi2HQ2d0MI33WTJcVQCeaYzfZu5+e19rXyLrqz90gkHC2GRhg0nbvzaZ/dTleVMHi Ju/sh1ihHwXE3nYwOx1RtXCuTwQm4s4CEoNBTq31gXTdVX168+72lIyYQYEutQgI6UwW 2Vnw== X-Gm-Message-State: AOJu0Yycj1ncaW+mBETJ6fScd1aiAeD2DIw3gl/KmFwblujC3sQ6jFho N913Nmn7jty7dMrO0S/TsDp782nk5ugxSPT/QzEWTujbteyXOr2+PMcS2QKJxVCCMoPFR3SWRE8 A X-Google-Smtp-Source: AGHT+IH3riRoxUpZsNolTqMmwUEi/L2akq/ZiKjuuvL66J8w6hxcvduQvHb81do9H1SOAKMZ+L7iDg== X-Received: by 2002:a2e:b0d2:0:b0:2ec:556f:3474 with SMTP id 38308e7fff4ca-2eeb318b5demr39410081fa.52.1720620896236; Wed, 10 Jul 2024 07:14:56 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266f7430ffsm84124195e9.44.2024.07.10.07.14.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:14:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v48 07/12] hw/sd/sdcard: Implement eMMC sleep state (CMD5) Date: Wed, 10 Jul 2024 16:14:03 +0200 Message-ID: <20240710141408.69275-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Luc Michel The JEDEC standards specifies a sleep state where the eMMC won't answer any command appart from RESET and WAKEUP and go to low power state. Implement this state and the corresponding command number 5. Signed-off-by: Luc Michel Signed-off-by: Francisco Iglesias Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3628686832..cf130ad1e3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1236,8 +1236,19 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { - sd->state = sd_idle_state; - sd_reset(DEVICE(sd)); + if (sd->state == sd_sleep_state) { + switch (req.arg) { + case 0x00000000: + case 0xf0f0f0f0: + break; + default: + return sd_r0; + } + } + if (sd->state != sd_inactive_state) { + sd->state = sd_idle_state; + sd_reset(DEVICE(sd)); + } return sd_is_spi(sd) ? sd_r1 : sd_r0; } @@ -1294,6 +1305,30 @@ static sd_rsp_type_t emmc_cmd_SET_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD5 */ +static sd_rsp_type_t emmc_cmd_sleep_awake(SDState *sd, SDRequest req) +{ + bool do_sleep = extract32(req.arg, 15, 1); + + switch (sd->state) { + case sd_sleep_state: + if (!do_sleep) { + /* Awake */ + sd->state = sd_standby_state; + } + return sd_r1b; + + case sd_standby_state: + if (do_sleep) { + sd->state = sd_sleep_state; + } + return sd_r1b; + + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD6 */ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) { @@ -1696,6 +1731,7 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req) case sd_ready_state: case sd_identification_state: case sd_inactive_state: + case sd_sleep_state: return sd_invalid_state_for_cmd(sd, req); case sd_idle_state: if (!sd_is_spi(sd) && sd_req_get_rca(sd, req) != 0x0000) { @@ -2018,6 +2054,12 @@ int sd_do_command(SDState *sd, SDRequest *req, req->cmd &= 0x3f; } + if (sd->state == sd_sleep_state && req->cmd) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is sleeping\n"); + rtype = sd_r0; + goto send_response; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req->cmd)) { sd->card_status |= ILLEGAL_COMMAND; @@ -2467,6 +2509,7 @@ static const SDProto sd_proto_emmc = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [5] = {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, From patchwork Wed Jul 10 14:14:04 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: 1958871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=F0kKCgN+; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0LC4S6rz1xpd for ; Thu, 11 Jul 2024 00:17:23 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY73-0004HF-M4; Wed, 10 Jul 2024 10:16:05 -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 1sRY69-0000ET-AW for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:21 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY64-00040P-JS for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:08 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so5618835e9.1 for ; Wed, 10 Jul 2024 07:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620902; x=1721225702; 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=b7ehYhE9tvvAz6fFzsukIT0qODV6ZW2fst3dCf28V88=; b=F0kKCgN+8bBrYbgYxN+VMPC+Xyy9bifFZSHTHSWwd3xNjI2xE+ucm2ZeeGyJWphCth mBYi5D7WLEw4yFlToforyG4T4/mat51B6I4gM/i6KY2qISUb2FC5DhV5Qz3DjDwcSUEp EsETLhAxXSI2+N4Mx7lG3l8S5JQWYoLr5zxm01st1LDyGPK4wwyNTDqR3wae4i9AgYne TaA5gvlu/VMEFD3Z29qZ/vwh3U8B7/83HJxULo0uRwr75n1X+zvH8LlmHRF4k91DMmxL CaQdJesjq1IQmYmbkLms3blMM2hz6JaUhw+bs++1MPzzrNYNBKR8cffox7L2VZFwfMxW BnzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620902; x=1721225702; 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=b7ehYhE9tvvAz6fFzsukIT0qODV6ZW2fst3dCf28V88=; b=UUUvzDXzhLjoluDHpi+R7XIIcjzGwFjtNkUS6IgqQuOueJuEQI/dwpU7NuruwJ+O4A pf3iH2vPGst0PRDOCOiRqDJFYAzzkBq1SHzR1ULrSoLOzUpXRBJdvEiM4k37wSDDJ9kN j0Wcps4Qfon6GN7K/oGo/VC2Xr9fAoGmoJ9f6TWx+1jS1Hlx074yhHrdtq/xuPLQi0sp Wa7tMuqjhfq+eYfleFEwnxNPswdG69D9WPJRJaAv5MvOOgjw9icN2VbhBHX4CQgWEfOT URoduyFZiKq0uXZFzTnudATU3cW9fWg4Bc0ByuoUL+PLCdePSxDEzzDZ2bvVxbkP9u6z RAwQ== X-Gm-Message-State: AOJu0Yw/iXMIzCoPGLw1/7R9mf95dpYyDqVyiux8peylQ1V/ng6/3Epe K1EObdy/PWEhTDKXr4h59HBtIB0YjTv0/AZSXGPZR3Xd10hMd6yba7GkS3exUR2iWWhoy9QkOUD s X-Google-Smtp-Source: AGHT+IH3ezxkRs63BC0khqh9/EvuEPK07N77U5wpANA3gcoD/eBho3bhyfg4/+wBygz5EUZSzQ2KFw== X-Received: by 2002:a05:600c:63ce:b0:424:895c:b84b with SMTP id 5b1f17b1804b1-426722c5b9emr52177275e9.4.1720620902611; Wed, 10 Jul 2024 07:15:02 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266f6e097bsm85083135e9.6.2024.07.10.07.15.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Vincent Palatin , Sai Pavan Boddu , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= Subject: [PATCH v48 08/12] hw/sd/sdcard: Add emmc_cmd_SEND_EXT_CSD handler (CMD8) Date: Wed, 10 Jul 2024 16:14:04 +0200 Message-ID: <20240710141408.69275-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Vincent Palatin The parameters mimick a real 4GB eMMC, but it can be set to various sizes. Signed-off-by: Vincent Palatin Signed-off-by: Cédric Le Goater Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Cédric Le Goater EXT_CSD values from Vincent's patch simplivied for Spec v4.3: - Remove deprecated keys: . EXT_CSD_SEC_ERASE_MULT . EXT_CSD_SEC_TRIM_MULT - Set some keys to not defined / implemented: . EXT_CSD_HPI_FEATURES . EXT_CSD_BKOPS_SUPPORT . EXT_CSD_SEC_FEATURE_SUPPORT . EXT_CSD_ERASE_TIMEOUT_MULT . EXT_CSD_PART_SWITCH_TIME . EXT_CSD_OUT_OF_INTERRUPT_TIME - Simplify: . EXT_CSD_ACC_SIZE (6 -> 1) 16KB of super_page_size -> 512B (BDRV_SECTOR_SIZE) . EXT_CSD_HC_ERASE_GRP_SIZE (4 -> 1) . EXT_CSD_HC_WP_GRP_SIZE (4 -> 1) . EXT_CSD_S_C_VCC[Q] (8 -> 1) . EXT_CSD_S_A_TIMEOUT (17 -> 1) . EXT_CSD_CARD_TYPE (7 -> 3) Dual data rate -> High-Speed mode - Update: . EXT_CSD_CARD_TYPE (7 -> 3) High-Speed MultiMediaCard @ 26MHz & 52MHz . Performances (0xa -> 0x46) Class B at 3MB/s. -> Class J at 21MB/s . EXT_CSD_REV (5 -> 3) Rev 1.5 (spec v4.41) -> Rev 1.3 (spec v4.3) - Use load/store API to set EXT_CSD_SEC_CNT - Remove R/W keys, normally zeroed at reset . EXT_CSD_BOOT_INFO Migrate the Modes segment (192 lower bytes) but not the full EXT_CSD register, see Spec v4.3, chapter 8.4 "Extended CSD register": The Extended CSD register defines the card properties and selected modes. It is 512 bytes long. The most significant 320 bytes are the Properties segment, which defines the card capabilities and cannot be modified by the host. The lower 192 bytes are the Modes segment, which defines the configuration the card is working in. These modes can be changed by the host by means of the SWITCH command. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cf130ad1e3..e6f1cc2066 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -124,6 +124,13 @@ struct SDState { uint16_t rca; uint32_t card_status; uint8_t sd_status[64]; + union { + uint8_t ext_csd[512]; + struct { + uint8_t ext_csd_rw[192]; /* Modes segment */ + uint8_t ext_csd_ro[320]; /* Properties segment */ + }; + }; /* Static properties */ @@ -476,6 +483,36 @@ static const uint8_t sd_csd_rw_mask[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, }; +static void mmc_set_ext_csd(SDState *sd, uint64_t size) +{ + uint32_t sectcount = size >> HWBLOCK_SHIFT; + + memset(sd->ext_csd, 0, sizeof(sd->ext_csd)); + + /* Properties segment (RO) */ + sd->ext_csd[EXT_CSD_S_CMD_SET] = 0b1; /* supported command sets */ + sd->ext_csd[EXT_CSD_BOOT_INFO] = 0x0; /* Boot information */ + sd->ext_csd[EXT_CSD_BOOT_MULT] = 0x8; /* Boot partition size. 128KB unit */ + sd->ext_csd[EXT_CSD_ACC_SIZE] = 0x1; /* Access size */ + sd->ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] = 0x01; /* HC Erase unit size */ + sd->ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] = 0x01; /* HC erase timeout */ + sd->ext_csd[EXT_CSD_REL_WR_SEC_C] = 0x1; /* Reliable write sector count */ + sd->ext_csd[EXT_CSD_HC_WP_GRP_SIZE] = 0x01; /* HC write protect group size */ + sd->ext_csd[EXT_CSD_S_C_VCC] = 0x01; /* Sleep current VCC */ + sd->ext_csd[EXT_CSD_S_C_VCCQ] = 0x01; /* Sleep current VCCQ */ + sd->ext_csd[EXT_CSD_S_A_TIMEOUT] = 0x01; /* Sleep/Awake timeout */ + stl_le_p(&sd->ext_csd[EXT_CSD_SEC_CNT], sectcount); /* Sector count */ + sd->ext_csd[210] = 0x46; /* Min write perf for 8bit@52Mhz */ + sd->ext_csd[209] = 0x46; /* Min read perf for 8bit@52Mhz */ + sd->ext_csd[208] = 0x46; /* Min write perf for 4bit@52Mhz */ + sd->ext_csd[207] = 0x46; /* Min read perf for 4bit@52Mhz */ + sd->ext_csd[206] = 0x46; /* Min write perf for 4bit@26Mhz */ + sd->ext_csd[205] = 0x46; /* Min read perf for 4bit@26Mhz */ + sd->ext_csd[EXT_CSD_CARD_TYPE] = 0b11; + sd->ext_csd[EXT_CSD_STRUCTURE] = 2; + sd->ext_csd[EXT_CSD_REV] = 3; +} + static void emmc_set_csd(SDState *sd, uint64_t size) { int hwblock_shift = HWBLOCK_SHIFT; @@ -512,6 +549,7 @@ static void emmc_set_csd(SDState *sd, uint64_t size) ((hwblock_shift << 6) & 0xc0); sd->csd[14] = 0x00; sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; + mmc_set_ext_csd(sd, size); } static void sd_set_csd(SDState *sd, uint64_t size) @@ -847,6 +885,24 @@ static const VMStateDescription sd_ocr_vmstate = { }, }; +static bool vmstate_needed_for_emmc(void *opaque) +{ + SDState *sd = opaque; + + return sd_is_emmc(sd); +} + +static const VMStateDescription emmc_extcsd_vmstate = { + .name = "sd-card/ext_csd_modes-state", + .version_id = 1, + .minimum_version_id = 1, + .needed = vmstate_needed_for_emmc, + .fields = (const VMStateField[]) { + VMSTATE_UINT8_ARRAY(ext_csd_rw, SDState, 192), + VMSTATE_END_OF_LIST() + }, +}; + static int sd_vmstate_pre_load(void *opaque) { SDState *sd = opaque; @@ -894,6 +950,7 @@ static const VMStateDescription sd_vmstate = { }, .subsections = (const VMStateDescription * const []) { &sd_ocr_vmstate, + &emmc_extcsd_vmstate, NULL }, }; @@ -1405,6 +1462,17 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) return sd_r7; } +/* CMD8 */ +static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) +{ + if (sd->state != 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) { @@ -2334,6 +2402,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 */ @@ -2511,6 +2580,7 @@ static const SDProto sd_proto_emmc = { [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [8] = {0, sd_adtc, "SEND_EXT_CSD", emmc_cmd_SEND_EXT_CSD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {1, sd_adtc, "READ_DAT_UNTIL_STOP", sd_cmd_unimplemented}, From patchwork Wed Jul 10 14:14:05 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: 1958872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=AU/55esw; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0LK57yJz1xpd for ; Thu, 11 Jul 2024 00:17:29 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY73-000472-TZ; Wed, 10 Jul 2024 10:16:05 -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 1sRY6J-0000az-Lr for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:25 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY6A-00040y-I1 for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:17 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4266f344091so17264415e9.0 for ; Wed, 10 Jul 2024 07:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620908; x=1721225708; 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=/gFRB+hAQA0cGPCvSBja+2xdFZOixPnxHszPhshqLtU=; b=AU/55esw4Ppl7nxlbKx3ZFJSQXKMmNiMDtWxZW7GhvEMYijYJesNM1/j/uL32v3pRO aii7oHAKiNQnYe8WNoe/nh5wIrkz4c+WaD7bVYD8+09svjb3P2ZNwAkvZexJ2aPILNkI MWTregUEI/FurPiNQC1kfQbxNHtQ7vcRcJa7o3aY4s6lqoOQNj61fDMhLWsFggtIKfJy t5pw+6DeisAykZCLQddmNjCNvcRBbOzG2tz23tDoF4y8qNMbp9jONlHDI1VcdCIbES6P 37nGX5bralsjGpgF7A7UuWvdQd4YF+ipJdIbFutyZktnsfTX7AbF9v8TkOKn7KPibOBH qx0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620908; x=1721225708; 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=/gFRB+hAQA0cGPCvSBja+2xdFZOixPnxHszPhshqLtU=; b=HpYas9Ke+t981/Yu+jp0Cz8+cUxk5sctyxtYYp/FyRFtHoMSl2rwFzwXuo9E5kEQTK lB+aT7Jg7PrkmgCAnaJA75axVyRFswUXeAy6cz60B4m75W0vSvyqw/bA6HRDzVlyvQ0B bqTl46tz6S4dU3i2VPkV/4lVAXct/y+9G1eY+HuDnRPsFk3NdkuYSq6sCKJxAeXPfgPg M+V9/75Ib3qmMq1pHdIpzG+8McLi2EIs+oXNlNV7V+T5EdMcUmIR74Ypv4jNM40ay5LH rjvtGbDVdvLncK42FJKc+3+mML/8I0D5EwmhZzrSOnSHWqzn1eJlreJm8qQ+oStT8m77 kcew== X-Gm-Message-State: AOJu0YyoR1SeTGEE5o99vcJNdqQ6Y2b4Mol+cXYL+PakGcteOBi5KPk+ 70UFu+jAnWn1IZsNVSHPHbNcPOmSIqPpM3pchaDo5uynf08wdBKR2hjpo8TDDeX0qqIcVKxjudP B X-Google-Smtp-Source: AGHT+IFsZOE/9ddoaD7izWA3qSqUtYCPOBw3Fw0GmWgEmmH71KVWWF7h6t7a8DUiD5Z9eXPWYGQaNg== X-Received: by 2002:a05:600c:257:b0:426:6308:e2f0 with SMTP id 5b1f17b1804b1-426707f8fbamr33784475e9.26.1720620908457; Wed, 10 Jul 2024 07:15:08 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4279731a60dsm9464315e9.40.2024.07.10.07.15.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:08 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 09/12] hw/sd/sdcard: Add eMMC 'boot-size' property Date: Wed, 10 Jul 2024 16:14:05 +0200 Message-ID: <20240710141408.69275-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Avoid hardcoding 1MiB boot size in EXT_CSD_BOOT_MULT, expose it as QOM property. By default, do not use any size. The board is responsible to set the boot size property. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e6f1cc2066..57a9eb91d0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -135,6 +135,7 @@ struct SDState { /* Static properties */ uint8_t spec_version; + uint64_t boot_part_size; BlockBackend *blk; const SDProto *proto; @@ -492,7 +493,8 @@ static void mmc_set_ext_csd(SDState *sd, uint64_t size) /* Properties segment (RO) */ sd->ext_csd[EXT_CSD_S_CMD_SET] = 0b1; /* supported command sets */ sd->ext_csd[EXT_CSD_BOOT_INFO] = 0x0; /* Boot information */ - sd->ext_csd[EXT_CSD_BOOT_MULT] = 0x8; /* Boot partition size. 128KB unit */ + /* Boot partition size. 128KB unit */ + sd->ext_csd[EXT_CSD_BOOT_MULT] = sd->boot_part_size / (128 * KiB); sd->ext_csd[EXT_CSD_ACC_SIZE] = 0x1; /* Access size */ sd->ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] = 0x01; /* HC Erase unit size */ sd->ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] = 0x01; /* HC erase timeout */ @@ -2704,6 +2706,7 @@ static Property sd_properties[] = { }; static Property emmc_properties[] = { + DEFINE_PROP_UINT64("boot-size", SDState, boot_part_size, 0), DEFINE_PROP_END_OF_LIST() }; From patchwork Wed Jul 10 14:14:06 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: 1958873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=mBEglw/v; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0Lf3vcxz1xpd for ; Thu, 11 Jul 2024 00:17:46 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY6s-00035L-W7; Wed, 10 Jul 2024 10:15:55 -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 1sRY6W-0001Au-Lq for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:38 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY6J-0004CJ-74 for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:30 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2eaa89464a3so67345151fa.3 for ; Wed, 10 Jul 2024 07:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620914; x=1721225714; 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=xkDhVRq7nOrp337t4BirLj66Emh0tyYky1+9xyZk6N0=; b=mBEglw/vxaYJTQyGjFtmt4wRkJb33G63aDCZfvJbMRmvZHQ3OBWQ/FMzNV8zpgDsk0 rEws8b5OGmEOPs5K+15fq89DqSYZHr9B4VKAEd60tbuFs/dwrIuqUfwv8zTEm9EjLiur H5kh2Ld+KHMip2fDmSCtVVkNPC9ckpWwqsZ/GXUNA4IiNQw9EwE/+mlJggFEVfTgP6to w1W2ClnMN9hxecqEJewF3zu5IiJyoTo1YBAzI+qvdOZDzSez9LJ+1gZYR93DKvCU6+ZK 1OrE1KwpEwPML/j4gOnZGihLUfLP96if31tw1x4hRP177OEY8iago/1LjH1CzysQ1Flc bAcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620914; x=1721225714; 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=xkDhVRq7nOrp337t4BirLj66Emh0tyYky1+9xyZk6N0=; b=E+X/efofXzf0pDLyUQSS+eoB71L6uBnxLWJDiy0sCD6r+NdxHdOk2PbcA1dnxf6jMK KIOORyQFXQ/8BhmQZnfHYb7Z5nhCBT5z+CTkg27H8+35r0ZDXXy5sm67UEl5vvSVjfSA WZQgm5GhBcI78gpENA11T5oSi+DGsAOfC+jl4nSPw/tX1dPxDa1cb+4nfbBG9narUiA1 IsUaVYjep2IuQ5iOgvJYkY72IP0cid7JkncJNiSrkUA+9ofcwxAmmME5fO78AnsU88MV TRPImvyRVdpnZmx2NGLk7pYcJxNdS82Mpw4S09T13WCafaiG5qeqnLU2Yq32wWLK3iWB fLBQ== X-Gm-Message-State: AOJu0YzvcYporX1k/yirneWVmt8kxQ6pr5IXOH57I9VCrHSDTL47Gun4 dk0E0AgF9DEA611GEIDMqRtBT8aniI15cnOaCSygPXcGNX+61FBKMICekK+vUF5HHMQOsz/2MxU k X-Google-Smtp-Source: AGHT+IHmW6W3R2Mlc6AHsVYFpU68k0NIZresqSdsEt9yGjslc6KJXVNCmJThUQZpSktbUx2C/H96sQ== X-Received: by 2002:a05:651c:2129:b0:2ee:87ef:825a with SMTP id 38308e7fff4ca-2eeb3198757mr41817341fa.53.1720620914561; Wed, 10 Jul 2024 07:15:14 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42662315363sm163329185e9.26.2024.07.10.07.15.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 10/12] hw/sd/sdcard: Implement eMMC 'boot-mode' Date: Wed, 10 Jul 2024 16:14:06 +0200 Message-ID: <20240710141408.69275-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=philmd@linaro.org; helo=mail-lj1-x234.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Spec v4.3 chapter 7.2.2 "Boot operation": If the CMD line is held LOW for 74 clock cycles and more after power-up before the first command is issued, the slave recognizes that boot mode is being initiated and starts preparing boot data internally. Track uptime since last reset, add the sd_uptime_ns() helper. When the first command is received, check at least 74 clocks are elapsed (during the identification phase, at a 10kHz rate) then enable BOOT_MODE in the Ext_CSD register. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/sd/trace-events | 1 + 2 files changed, 39 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 57a9eb91d0..c2ea942389 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -163,6 +163,8 @@ struct SDState { */ bool expecting_acmd; uint32_t blk_written; + int64_t reset_time_ns; + uint32_t cmd_count; uint64_t data_start; uint32_t data_offset; @@ -352,6 +354,11 @@ static uint8_t sd_crc7(const void *message, size_t width) return shift_reg; } +static int64_t sd_uptime_ns(SDState *sd) +{ + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - sd->reset_time_ns; +} + /* Operation Conditions register */ #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ @@ -479,6 +486,10 @@ static void emmc_set_cid(SDState *sd) #define CMULT_SHIFT 9 /* 512 times HWBLOCK_SIZE */ #define WPGROUP_SIZE (1 << (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)) +#define OD_FREQ_MIN_HZ 10000 +#define OD_FREQ_MAX_HZ 400000 +#define BOOT_MODE_DELAY_CYCLES_MIN 74 + static const uint8_t sd_csd_rw_mask[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, @@ -797,6 +808,8 @@ static void sd_reset(DeviceState *dev) sect = sd_addr_to_wpnum(size) + 1; + sd->reset_time_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + sd->cmd_count = 0; sd->state = sd_idle_state; /* card registers */ @@ -905,6 +918,18 @@ static const VMStateDescription emmc_extcsd_vmstate = { }, }; +static const VMStateDescription sdmmc_uptime_cmdcnt_vmstate = { + .name = "sd-card/uptime-command_count-state", + .version_id = 1, + .minimum_version_id = 1, + .needed = vmstate_needed_for_emmc, + .fields = (const VMStateField[]) { + VMSTATE_INT64(reset_time_ns, SDState), + VMSTATE_UINT32(cmd_count, SDState), + VMSTATE_END_OF_LIST() + }, +}; + static int sd_vmstate_pre_load(void *opaque) { SDState *sd = opaque; @@ -953,6 +978,7 @@ static const VMStateDescription sd_vmstate = { .subsections = (const VMStateDescription * const []) { &sd_ocr_vmstate, &emmc_extcsd_vmstate, + &sdmmc_uptime_cmdcnt_vmstate, NULL }, }; @@ -1925,6 +1951,16 @@ static sd_rsp_type_t sd_cmd_SEND_OP_COND(SDState *sd, SDRequest req) sd->state = sd_ready_state; } + if (sd_is_emmc(sd) && sd->cmd_count == 1) { + int64_t clk_cycles = sd_uptime_ns(sd) / OD_FREQ_MIN_HZ; + + trace_sdcard_ext_csd_bootmode(sd_uptime_ns(sd), clk_cycles, + clk_cycles > BOOT_MODE_DELAY_CYCLES_MIN); + if (clk_cycles > BOOT_MODE_DELAY_CYCLES_MIN) { + sd->ext_csd[EXT_CSD_PART_CONFIG] |= (1 << 3); + } + } + return sd_r3; } @@ -2107,6 +2143,8 @@ int sd_do_command(SDState *sd, SDRequest *req, return 0; } + ++sd->cmd_count; + if (sd->state == sd_inactive_state) { rtype = sd_illegal; goto send_response; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 5dfe6be7b7..7d0de368aa 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -57,6 +57,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, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint64_t size, uint32_t blklen) "%s %20s/ CMD%02d ofs %"PRIu32" size %"PRIu64" blklen %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" +sdcard_ext_csd_bootmode(int64_t uptime_ns, int64_t clk_cycles, unsigned enabled) "%"PRId64" ns, %"PRId64" cycles, boot mode: %u" # pxa2xx_mmci.c pxa2xx_mmci_read(uint8_t size, uint32_t addr, uint32_t value) "size %d addr 0x%02x value 0x%08x" From patchwork Wed Jul 10 14:14:07 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: 1958870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=QXcdP26S; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0KX56j0z1xpd for ; Thu, 11 Jul 2024 00:16:48 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY79-0004oK-5f; Wed, 10 Jul 2024 10:16:11 -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 1sRY6T-00014M-VZ for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:37 -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 1sRY6N-0004D4-TO for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:27 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ee920b0781so61941561fa.1 for ; Wed, 10 Jul 2024 07:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620921; x=1721225721; 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=hPJuLdFySqbB/CKG7NXWhHEyoFtSqzHM/Pbd2zf5s6o=; b=QXcdP26SaUFN9uW93ilkP/Ztnj9/RV+t3Pyb1Osm05g9DYmQzBUUrFb5mJlWT0Bar4 7IZjpYEG2XWklsWfRPsmJmtSWnZECG8lstR+qNf4W1o1wFHkNbZGBFwv9nAEcyzbksGI 6CRtSGJcefXbExd1vNaefSc6eUsq0wIC7lD7zODr9B5wlcMG3vKFrTN1drL+Ipj8mKLu r17Yhx70rHmowvaHKkOYrvw2AmRKvl8OE0pDZPWimn14QwqItpGAJSznHcpvJ3G5sv2x w2dNz3wi/R7kIYVrl+Y+F/bceNSNPnTxdac6p/VMA3Q7bxFVPTvbia0qdBYVhErENa77 NB1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620921; x=1721225721; 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=hPJuLdFySqbB/CKG7NXWhHEyoFtSqzHM/Pbd2zf5s6o=; b=h6uIAQCUvzmr1FlcsSpcTUONSgbDSY8UU3uZvpTsyp5GUCVU3pRkqRbOrWwcz5t9If lhpldZHl6dmTZortkaxRmtVsmxAQodvdUAvaegLSM/nceGmI9f7zil0jTvRoDdTEPsMI bBSELMsKohvH3rBt/EkqJH/ifgZWFBUb8tyvtpQXOIcAp1ZqqA0XLsto8X19pxlG8iVI jlnTiFGvBqK3i+TxqPoivMXUCClWvapB5ON/2jhHRIdDlNWPPClrvhgVQsUsrgaqpEoH ePC/d8XzubY1KvCFYQuFvec3q61Q08KOZw6aInfQMgrlrj9nmkhyy23GiYcQ19mO7iQR 6ohA== X-Gm-Message-State: AOJu0YwC4g9QHknaW2XcnX8KbXEXy3clFDjVlKCMRz9nzalpj0kCkJwG yMOwWlW0ama8zDMPxw/G74h/jHxt8ijtwxqSaLaqkpY+qOjq2Vt5TYPuBwKG/p4MEATjOupcOH0 D X-Google-Smtp-Source: AGHT+IEMZ9gq3s6MML2Entilt3R7oWZFc/TTzEwK67IAmGg8i9pO/kFP/Jwd8jr6sEx5SidNbsm5ow== X-Received: by 2002:a2e:9e89:0:b0:2ec:617b:4757 with SMTP id 38308e7fff4ca-2eeb30de2e6mr34702611fa.13.1720620920674; Wed, 10 Jul 2024 07:15:20 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4267255858asm49816875e9.0.2024.07.10.07.15.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Sai Pavan Boddu , "Edgar E . Iglesias" Subject: [PATCH v48 11/12] hw/sd/sdcard: Add mmc SWITCH function support (CMD6) Date: Wed, 10 Jul 2024 16:14:07 +0200 Message-ID: <20240710141408.69275-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-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=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Sai Pavan Boddu switch operation in mmc cards, updated the ext_csd register to request changes in card operations. Here we implement similar sequence but requests are mostly dummy and make no change. Implement SWITCH_ERROR if the write operation offset goes beyond length of ext_csd. Signed-off-by: Sai Pavan Boddu Signed-off-by: Edgar E. Iglesias Signed-off-by: Cédric Le Goater Reviewed-by: Philippe Mathieu-Daudé [PMD: Convert to SDProto handlers, add trace events] Signed-off-by: Philippe Mathieu-Daudé Tested-by: Andrew Jeffery --- hw/sd/sd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ hw/sd/trace-events | 2 ++ 2 files changed, 58 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c2ea942389..86b857d414 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -653,6 +653,7 @@ static bool sd_req_rca_same(SDState *s, SDRequest req) FIELD(CSR, AKE_SEQ_ERROR, 3, 1) FIELD(CSR, APP_CMD, 5, 1) FIELD(CSR, FX_EVENT, 6, 1) +FIELD(CSR, SWITCH_ERROR, 7, 1) FIELD(CSR, READY_FOR_DATA, 8, 1) FIELD(CSR, CURRENT_STATE, 9, 4) FIELD(CSR, ERASE_RESET, 13, 1) @@ -1117,6 +1118,47 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) return ret; } +enum ExtCsdAccessMode { + EXT_CSD_ACCESS_MODE_COMMAND_SET = 0, + EXT_CSD_ACCESS_MODE_SET_BITS = 1, + EXT_CSD_ACCESS_MODE_CLEAR_BITS = 2, + EXT_CSD_ACCESS_MODE_WRITE_BYTE = 3 +}; + +static void mmc_function_switch(SDState *sd, uint32_t arg) +{ + uint8_t access = extract32(arg, 24, 2); + uint8_t index = extract32(arg, 16, 8); + uint8_t value = extract32(arg, 8, 8); + uint8_t b = sd->ext_csd[index]; + + trace_sdcard_switch(access, index, value, extract32(arg, 0, 2)); + + if (index >= 192) { + qemu_log_mask(LOG_GUEST_ERROR, "MMC switching illegal offset\n"); + sd->card_status |= R_CSR_SWITCH_ERROR_MASK; + return; + } + + switch (access) { + case EXT_CSD_ACCESS_MODE_COMMAND_SET: + qemu_log_mask(LOG_UNIMP, "MMC Command set switching not supported\n"); + return; + case EXT_CSD_ACCESS_MODE_SET_BITS: + b |= value; + break; + case EXT_CSD_ACCESS_MODE_CLEAR_BITS: + b &= ~value; + break; + case EXT_CSD_ACCESS_MODE_WRITE_BYTE: + b = value; + break; + } + + trace_sdcard_ext_csd_update(index, sd->ext_csd[index], b); + sd->ext_csd[index] = b; +} + static void sd_function_switch(SDState *sd, uint32_t arg) { int i, mode, new_func; @@ -1428,6 +1470,19 @@ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); } +static sd_rsp_type_t emmc_cmd_SWITCH(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_transfer_state: + sd->state = sd_programming_state; + mmc_function_switch(sd, req.arg); + sd->state = sd_transfer_state; + return sd_r1b; + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD7 */ static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req) { @@ -2619,6 +2674,7 @@ static const SDProto sd_proto_emmc = { [3] = {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake}, + [6] = {10, sd_adtc, "SWITCH", emmc_cmd_SWITCH}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [8] = {0, sd_adtc, "SEND_EXT_CSD", emmc_cmd_SEND_EXT_CSD}, [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 7d0de368aa..5454e55077 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -58,6 +58,8 @@ sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint64_t size, uint32_t blklen) "%s %20s/ CMD%02d ofs %"PRIu32" size %"PRIu64" blklen %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" sdcard_ext_csd_bootmode(int64_t uptime_ns, int64_t clk_cycles, unsigned enabled) "%"PRId64" ns, %"PRId64" cycles, boot mode: %u" +sdcard_ext_csd_update(unsigned index, uint8_t oval, uint8_t nval) "index %u: 0x%02x -> 0x%02x" +sdcard_switch(unsigned access, unsigned index, unsigned value, unsigned set) "SWITCH acc:%u idx:%u val:%u set:%u" # pxa2xx_mmci.c pxa2xx_mmci_read(uint8_t size, uint32_t addr, uint32_t value) "size %d addr 0x%02x value 0x%08x" From patchwork Wed Jul 10 14:14:08 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: 1958869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=f+gtcbBt; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WK0KK3KHxz1xpd for ; Thu, 11 Jul 2024 00:16:37 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRY7A-0005Xy-9b; Wed, 10 Jul 2024 10:16:12 -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 1sRY6m-0002DQ-GT for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:49 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY6W-0004Ek-AM for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:48 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-36798e62aeeso4244983f8f.1 for ; Wed, 10 Jul 2024 07:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620926; x=1721225726; 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=E592VUjNM/e32MWHdD7KwMvGh3P49D6D0LHQIn1oaLY=; b=f+gtcbBtKrwwRBjIxCkoZUpe7GC7ZnimP78p8wUbldvdcJsZSlfJ1lfeuv5Fv7csd7 j1tnaooeo9r4NdmIY1rG1Hbfvn0voNLrW+wh2x7ymSjrSHE/vQmVfScFUmBVgITWd6qW 5Rl9ZTWOPVHyXzMnDdJG509cPB15xafckqg6DXWxd/6VPORYdCQeO50NW6XJTh37nI1B 0Rts45t/NjSp3RByiQrNs+W5BmwsMzo4/jSFFvj+0RZmi0vXkvpjy34BzNirYi8mCn7r IaJdySSbu0dZQ8GPQQY09Tq1Qujthdp+L9tRsD0GNmWD5y1hj3uAmvSEhJSpJzk8Y6uX avMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620926; x=1721225726; 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=E592VUjNM/e32MWHdD7KwMvGh3P49D6D0LHQIn1oaLY=; b=tJObPlczPsaMIllKBPui7i3PsddqvfIuHss3VLru01kJSNTsvmtBrphPd1FypZ6RMM 2RUTAdUReRqKwq7mQgaw14fL6WCRwUv9bceBm0mwYxposZO+BLds2KPfjon98H33dLCg wht7SMrAzEAtNMQQNlZwau/iP/flHwXyhLozsG1WKfSWfVNKS7JTY4tbTlsrCFHTF9OI 0WbR8Ov0iFIDw+8TwURhvwXD6fsgnyM9B8mnns8pSNOOvUXnsjPfl0VnK/kzMUYU0tnq yo2pqMZ5AbcVJZSlJX/24riuEobPz8eBCzOg/onABM+jWqdQ7uK28zN/HL9HK0mFpi0x pfWw== X-Gm-Message-State: AOJu0Yz6ne2LamtLVdAn4FQRAPGWuDTLlyPEO0ljAdCkTlOiyNch72w2 Yh6kg8dx1TwqC+834Z/uAPIb2xAsKnTkczQe9GMc+LZoLHBA9IsAPyTRbW3YOoREaylGDK/U0xX h X-Google-Smtp-Source: AGHT+IGzmVXduSvpxciVazkyRa9xURlFZEQnmCrmjjc4MZ1v5Y4aPM1pbwcjxC5QJC2ArB1pamsWWQ== X-Received: by 2002:adf:fdc3:0:b0:367:8a2f:a6dc with SMTP id ffacd0b85a97d-367cead15b8mr3771606f8f.44.1720620926710; Wed, 10 Jul 2024 07:15:26 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfab161sm5414331f8f.91.2024.07.10.07.15.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 12/12] hw/sd/sdcard: Support boot area in emmc image Date: Wed, 10 Jul 2024 16:14:08 +0200 Message-ID: <20240710141408.69275-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Joel Stanley This assumes a specially constructed image: dd if=/dev/zero of=mmc-bootarea.img count=2 bs=1M dd if=u-boot-spl.bin of=mmc-bootarea.img conv=notrunc dd if=u-boot.bin of=mmc-bootarea.img conv=notrunc count=64 bs=1K cat mmc-bootarea.img obmc-phosphor-image.wic > mmc.img truncate --size 16GB mmc.img For now this still requires a mtd image to load the SPL: qemu-system-arm -M tacoma-bmc -nographic \ -global driver=sd-card,property=emmc,value=true \ -drive file=mmc.img,if=sd,index=2,format=raw Signed-off-by: Joel Stanley Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 86b857d414..8c68494b8b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -774,6 +774,40 @@ static uint32_t sd_blk_len(SDState *sd) return sd->blk_len; } +/* + * This requires a disk image that has two boot partitions inserted at the + * beginning of it. The size of the boot partitions is the "boot-size" + * property. + */ +static uint32_t sd_bootpart_offset(SDState *sd) +{ + bool partitions_enabled; + unsigned partition_access; + + if (!sd->boot_part_size || !sd_is_emmc(sd)) { + return 0; + } + + partitions_enabled = sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_EN_MASK; + if (!partitions_enabled) { + return 0; + } + + partition_access = sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_ACC_MASK; + switch (partition_access) { + case EXT_CSD_PART_CONFIG_ACC_DEFAULT: + return sd->boot_part_size * 2; + case EXT_CSD_PART_CONFIG_ACC_BOOT0: + return 0; + case EXT_CSD_PART_CONFIG_ACC_BOOT0 + 1: + return sd->boot_part_size * 1; + default: + g_assert_not_reached(); + } +} + static uint64_t sd_req_get_address(SDState *sd, SDRequest req) { uint64_t addr; @@ -806,6 +840,7 @@ static void sd_reset(DeviceState *dev) sect = 0; } size = sect << HWBLOCK_SHIFT; + size -= sd_bootpart_offset(sd); sect = sd_addr_to_wpnum(size) + 1; @@ -1029,6 +1064,7 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_read_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); } @@ -1037,6 +1073,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_write_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); }