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: 811783 Delivered-To: patch@linaro.org Received: by 2002:adf:ee12:0:b0:367:895a:4699 with SMTP id y18csp775852wrn; Wed, 10 Jul 2024 07:16:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUoJwsOXVMBgjafOhdwdFgDWqRiV0S7pQct+kEiwSZ9UIR0KJuswERbP/GY1k2ns3bYlvbOxCyQ6GyvLqrB/4N/ X-Google-Smtp-Source: AGHT+IHQd6588imZNog1z+jWC/BwvNXls4oC4n7xBW8xJ4sODTwAfQ8KM6XcsIEEXCArzJFlCfIK X-Received: by 2002:a05:620a:269b:b0:79f:78a:f7b4 with SMTP id af79cd13be357-79f19a805aamr743358585a.42.1720621007368; Wed, 10 Jul 2024 07:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720621007; cv=none; d=google.com; s=arc-20160816; b=x+UYDnou9GIGfIVzG2Xv+EVEPXW9QvA0biEFG2AaC3StmMMisdIPji64imeD/mz9WJ hmraZBBudxKmnlySag9syJW1PvKTpL4TBehhDHZqY59TqjE5PM+vFqzBJdaFgElkeFOP PpUaVH2RcAGC2YiVbHNKuKTtyPzdM2cIIavduqZ60gCaL6DN7kgKga0uriZmknO9yAhk 8TvLaH5BsH5uGVFmuDvJ3CQzP28PEufzBh0p9oV678UZSNx/NMIND9YCQRP1U6AwFbG+ vIU8hRMfzEXcwmaS75m2CIraitAOBQMhIIw+1i8GT5FIPitahw94kszxmU/F8ZLMcsFA DpBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hPJuLdFySqbB/CKG7NXWhHEyoFtSqzHM/Pbd2zf5s6o=; fh=5U3F8GtES6dj2B8qBKDevCLeC6fbD2Iz+Sr+FoyvoFw=; b=m4XnNWpF+gUWymAqPvZjMzV2z/bUEvO3cOmpEzmFJX6YNT/SE56oRmHBNnTjfRjyhP Eq8zT7txVioKX2/5ILPtYv8+FmewxdjF4WO7fn/jFpdrGqoX/ypBQYdZIRL1Q3xRupjY /k97Fm6blc2A1Yv7cstw+xy94yEsZuIaKdpCYlTkoMPBeokGzIhkEvTwspa6FsG7YGHI pErXGPONtFYmirZGQvJt+gAmiRwplG/mG4QSVyOxebWDQa03/se9nDERUol5hVaZ5uNq akC6IO16lGAVaUO5i/j9epgIsCkXrAz3XoOqG15f16ivCSWfqaxt8mM8gBJzBujzOcja zMUQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QXcdP26S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79f190bb4adsi523073185a.507.2024.07.10.07.16.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jul 2024 07:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QXcdP26S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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"