From patchwork Fri Jun 30 02:43:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 106657 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1787608qge; Thu, 29 Jun 2017 19:43:17 -0700 (PDT) X-Received: by 10.99.36.129 with SMTP id k123mr8546356pgk.230.1498790597567; Thu, 29 Jun 2017 19:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498790597; cv=none; d=google.com; s=arc-20160816; b=yFZm/H8p6sVGr49SSbYI1lLqKU1IiqrNnzaHUqJrHPLa3OSIeDGYuwabhB/bHuZgIR wRDL6JnyBZm4/ETlozLrxAEl/69sDNrwj9+923ll1YT0TxUmQjPziNCtUqyrL5qRUHdw 9PeR0fbut9sA/8jXNwZT7AnRrdU5g0h5BE6EAcI8dZ24JAc8MhEbhtiwRTe+4sM+tuEe GpeheEqvlRpROmSoHTzL77JtcKFu/4FdYeWo/anvy/OuQmN65YAwlExskWBi87vSwKut SHdsN4ot7rt1y29+/bQ/dvDBE1UkVDZIvnrB6AXOlMAObXVlFXIemF8q22qYENhBUB8G sb9g== 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=CqJHmmlVUygMxDqrysPBrFhMIN+VZJKduueNPkWMgdI=; b=a06IlZlAXoupNlZqrRaX6wvtFLShhGNlBUpJCQJ/AoJRtaBp6ii6+YGJhpb8pMjNx5 HcM4UlODSWBeyfKrJwzhRE8KMUzsi1s0IkbGzpQeF0CPAUg2qDeg58sN/ArMmUxB9MLX 8XuESxQv2RTgoFJI/To0Z8W1gPbs7GxpVBqr0aqOyXMMqTrfMGv5VLFdE7+dBG9y2GMo 1EX/V9xEmJhHpN+bNMLC0AE/17E6qCLT07FU4H5ouULnNQGbiJDV4wi+ucHaQNja7+am rwgJMKONDT7lWvpMNWw9nHdosJYHlWfDfD6vzUf/Ak/20LBAIS2fOI9Ld2+wdyr9het5 Lq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=h8Ef6XIE; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id e7si4831239pfg.409.2017.06.29.19.43.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 19:43:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=h8Ef6XIE; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 3B70B21CB57A2; Thu, 29 Jun 2017 19:41:43 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pf0-x230.google.com (mail-pf0-x230.google.com [IPv6:2607:f8b0:400e:c00::230]) (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 91E8321959CB2 for ; Thu, 29 Jun 2017 19:41:41 -0700 (PDT) Received: by mail-pf0-x230.google.com with SMTP id q86so59561605pfl.3 for ; Thu, 29 Jun 2017 19:43:14 -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=Mzmpc+yKXAe6FeH5+8oMUlIt6xsft8RBUvp5RiGXhr8=; b=h8Ef6XIERGqDDUS2cvCVqyJSKQE/kEUsqcgCq+wDmbtQuKwv7DGQOTM+INKj9+ijc8 zEmfJuUtPAtB8NbfwUls0Dk6ZULN8sfhmFnhVwOMN2MY+iWv/0RJ+fMKQ2aRH75GUWQ6 MRKkGuss7vo509+xw2dwYCQv/TuxSVQCl6hU4= 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=Mzmpc+yKXAe6FeH5+8oMUlIt6xsft8RBUvp5RiGXhr8=; b=TkMakfFBYUi6SEmtcINCucOFl9uN5kA8uwzh7qersAlrVeXjX/KDOayxswynM1ytqN 60NIwW+8khsKJkCiF8lb6td49zIrsE0PBlm16O+NVMbGAIMzxxSxCLGaBGEtEjOBBNqO N8vtPIJP4xr940Y5UHtAHxZq1sM5ZS6o/NaOxKR6blJTKZlB5Og36jfdJP09+M6PXGKc IzeBr2tuLyAVNja1r09wDHQZ2di9x5xwXgdXYeQGjBCwbYyL8K763XpElsE5LoggncT5 ChCT6Ee7NKDpZRC2ge0e+rKDwNnAadEKqMjfB7g6fnL9H86f2aMgD16UX5K1S7YaaheX 5VDw== X-Gm-Message-State: AKS2vOzrn0RmBazYy+8ymQc0eSg1DLW6vU2dG02QbVuHk6EL9zfMYRtJ ochEmCI+JN3nDCsN50K34A== X-Received: by 10.84.173.67 with SMTP id o61mr21489693plb.236.1498790594645; Thu, 29 Jun 2017 19:43:14 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.63]) by smtp.gmail.com with ESMTPSA id i5sm14490767pgr.40.2017.06.29.19.43.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 19:43:14 -0700 (PDT) From: Jun Nie To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, haojian.zhuang@linaro.org, edk2-devel@lists.01.org Date: Fri, 30 Jun 2017 10:43:00 +0800 Message-Id: <1498790580-11893-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v4] 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 | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 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..7f74c54 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c @@ -13,6 +13,7 @@ **/ #include +#include #include #include "Mmc.h" @@ -210,15 +211,19 @@ EmmcIdentificationMode ( } // Fetch ECSD + MmcHostInstance->CardInfo.ECSDData = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ECSD))); + if (MmcHostInstance->CardInfo.ECSDData == NULL) { + return EFI_OUT_OF_RESOURCES; + } 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; + goto FreePageExit; } // Make sure device exiting data mode @@ -226,7 +231,7 @@ EmmcIdentificationMode ( Status = EmmcGetDeviceState (MmcHostInstance, &State); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "EmmcIdentificationMode(): Failed to get device state, Status=%r.\n", Status)); - return Status; + goto FreePageExit; } } while (State == EMMC_DATA_STATE); @@ -237,12 +242,16 @@ 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 MmcHostInstance->CardInfo.CardType = EMMC_CARD; return EFI_SUCCESS; + +FreePageExit: + FreePages (MmcHostInstance->CardInfo.ECSDData, EFI_SIZE_TO_PAGES (sizeof (ECSD))); + return Status; } STATIC @@ -258,7 +267,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;