From patchwork Thu Jun 29 09:03:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 106623 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp850479qge; Thu, 29 Jun 2017 02:03:59 -0700 (PDT) X-Received: by 10.99.9.131 with SMTP id 125mr14498948pgj.178.1498727039696; Thu, 29 Jun 2017 02:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498727039; cv=none; d=google.com; s=arc-20160816; b=ELHf0hxkcH6ihYErNI4LrJls3ZCN5+35cWSekeJw3gG19L4cuobhVYdx15VysHntM5 /2EyhzpA7F1izuHo+wj112MquS/oTZ4F0QPu1mSmTO+QxFGcAj/s9KJ8CYSF9Zpc1nIE BpkNP0+rjRA80b3JhDmiqb9kylUqpcD+x8X1NE0OGUh8H7y83tsTLRllNZuPk70x7/T3 mhuIV+QUWWbizhHARJL4x9/uHwmlfVOSCTiulBJ4zyJJvHNPxjNHw5Nk2vtSidFbEiGM qHau4YbVVIXBuaY/ysKVP7HtYIhKLNoBWTxymLJXWGNwPGiL6LtlNBhOnU+QbhHksNS5 Ukmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=efBmrJ/nmKXUU6AcJI5H5xiErQc7RTFRYlQElDIXlZ4=; b=suKRCVIU9BNkK67vuirlTZDL5ruKoxI39omhhrUOSqPAZjO5zOet/e26MRBRvW84SD iXdjpir3mXfSZTKLI9LR3gvk8h7AsjKvMqFaPEIiWDKCdWzRZc5NJFOsdyufNGHqyIGh LJiDNazJ/NwM5zJHYMBVsex4ITF0caa8v97DttcikkRiz+3qmR82gZ2iBOt9lxxXQqmd jvEh7OJRKohXqwbvL/IOOwTR4SWxsZ6W5mnE6nDX3bKt4gJL5kAQfjFdYk7evuIiV6WC 5WzExQ9yatIlq7/GVfDRAvrNoIpSJasR6oKoVeIsU/DQKqkp+s3C+erRyKduqV6HYBaz VvNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=dMXIrB0/; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id v86si652307pfa.156.2017.06.29.02.03.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 02:03:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=dMXIrB0/; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 950AD21A00AD5; Thu, 29 Jun 2017 02:02:26 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x232.google.com (mail-pg0-x232.google.com [IPv6:2607:f8b0:400e:c05::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7E9F221B02B94 for ; Thu, 29 Jun 2017 02:02:25 -0700 (PDT) Received: by mail-pg0-x232.google.com with SMTP id j186so44878136pge.2 for ; Thu, 29 Jun 2017 02:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=jo5/QMs92SlBZukxCf7askJqfPqhcgchgWNJ9r820go=; b=dMXIrB0/RNy2GFAj60LoZB2UVLBn6ue5rYrAcS+8jhkADc9wo+vFgvevYacEnjeiYZ KF2bmCRyfzcYsCqgbhEU7rXcXDzOxu6dV/z9kyc+Wa8/ESbxl3K157Wf9C9VDJyUL0au bZY3DtitIC69YlrrkFTHldGJqudnYO+89KyhA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jo5/QMs92SlBZukxCf7askJqfPqhcgchgWNJ9r820go=; b=MXIk5FX4DKQTWfEUn2UTwEPBieuKrzBQqDUMkMumu4sWWNWf5d1xFXpVkUf1E9ApAo 0IU4KhmgLy+Yj/5sK1g5E90GU5cIidhL/o6MjfYjs5etq7j0fpHBE4/l5WLj3dn2u+hU quphd0yTQUw/WVvEWL1fuGfq5qmbSN1U4vwCoRgrQewE1BSo8rMMJsRF08ByOfRZ6k3H RMK+E2WqQAgkrVRTMQU3/2fyV2ZWdhtdBCmywLj7P+Lo/yIALIw4530rNDAh6GZxG4KJ zEdzU+T3Klr4ACupCEDkdXq/XBU9997luBB62GnpFsiGEYbkn2nc7AzOhveccHk/9mji ZZqg== X-Gm-Message-State: AKS2vOz3wSfmSer3Hm0KgiD4PNKR+nGlHXJvh8L+jL1jYAe2+R2HjVZy Ovbht+XKJJ462q8K X-Received: by 10.98.133.16 with SMTP id u16mr4324145pfd.140.1498727037746; Thu, 29 Jun 2017 02:03:57 -0700 (PDT) Received: from localhost.localdomain (60-249-20-69.HINET-IP.hinet.net. [60.249.20.69]) by smtp.gmail.com with ESMTPSA id a71sm10846909pfl.129.2017.06.29.02.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:03:57 -0700 (PDT) From: Jun Nie To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, haojian.zhuang@linaro.org, edk2-devel@lists.01.org Date: Thu, 29 Jun 2017 17:03:50 +0800 Message-Id: <1498727030-26410-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH] EmbeddedPkg/MmcDxe: Align the ExtCSD buffer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jason.liu@linaro.org, shawn.guo@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" ExtCSD structure may be read via DMA. So align it to page to avoid data corruption. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie --- EmbeddedPkg/Universal/MmcDxe/Mmc.h | 2 +- EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h b/EmbeddedPkg/Universal/MmcDxe/Mmc.h index 8a7d5a3..f3e56ff 100644 --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h @@ -319,7 +319,7 @@ typedef struct { OCR OCRData; CID CIDData; CSD CSDData; - ECSD ECSDData; // MMC V4 extended card specific + ECSD *ECSDData; // MMC V4 extended card specific } CARD_INFO; typedef struct _MMC_HOST_INSTANCE { diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c index c28207e..6bb65c3 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c @@ -13,6 +13,7 @@ **/ #include +#include #include #include "Mmc.h" @@ -210,12 +211,16 @@ EmmcIdentificationMode ( } // Fetch ECSD + MmcHostInstance->CardInfo.ECSDData = AllocatePages (1); + if (MmcHostInstance->CardInfo.ECSDData == NULL) { + return EFI_BUFFER_TOO_SMALL; + } Status = Host->SendCommand (Host, MMC_CMD8, 0); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status)); } - Status = Host->ReadBlockData (Host, 0, 512, (UINT32 *)&(MmcHostInstance->CardInfo.ECSDData)); + Status = Host->ReadBlockData (Host, 0, 512, (UINT32 *)MmcHostInstance->CardInfo.ECSDData); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "EmmcIdentificationMode(): ECSD read error, Status=%r.\n", Status)); return Status; @@ -237,7 +242,7 @@ EmmcIdentificationMode ( Media->LogicalBlocksPerPhysicalBlock = 1; Media->IoAlign = 4; // Compute last block using bits [215:212] of the ECSD - Media->LastBlock = MmcHostInstance->CardInfo.ECSDData.SECTOR_COUNT - 1; // eMMC isn't supposed to report this for + Media->LastBlock = MmcHostInstance->CardInfo.ECSDData->SECTOR_COUNT - 1; // eMMC isn't supposed to report this for // Cards <2GB in size, but the model does. // Setup card type @@ -258,7 +263,7 @@ InitializeEmmcDevice ( UINT32 TimingMode[4] = {EMMCHS52DDR1V2, EMMCHS52DDR1V8, EMMCHS52, EMMCHS26}; Host = MmcHostInstance->MmcHost; - ECSDData = &MmcHostInstance->CardInfo.ECSDData; + ECSDData = MmcHostInstance->CardInfo.ECSDData; if (ECSDData->DEVICE_TYPE == EMMCBACKWARD) return EFI_SUCCESS;