From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Cc: shawn.guo@linaro.org, jason.liu@linaro.org, Jun Nie 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: [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: , X-List-Received-Date: Thu, 29 Jun 2017 09:02:25 -0000 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(-) 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; -- 1.9.1