From patchwork Tue Jul 4 15:43:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 106992 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1145755qge; Tue, 4 Jul 2017 08:43:40 -0700 (PDT) X-Received: by 10.98.135.140 with SMTP id i134mr15678138pfe.237.1499183020025; Tue, 04 Jul 2017 08:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499183020; cv=none; d=google.com; s=arc-20160816; b=cYChAgqhhOp5MlEk+eA6uNAnqktKJuN/KFyzD0IQGY8fgxT/XEmcn3yK5rGa+EQ7k/ JT0Edwmw03dmVIsCtbNi/eAHfF1T10DgH+q4knqT1iwWsi86/bPr0s653r47qYwjyWph JvBt7v6iWu9uu2w7gD5MSSkQRS3Doii58n2BH+yXwyZDNJGfRG/sZ52S63DGvSdGyTOb 4aI1UQElo5En3rdTL1ywHV5Ztr2YnJ7dqck1pYEzP8s0N6jksMbAp4qGQJgxjFD5yCmC DL0Gwrno43/HMwr2zMYlvpBD2in1H34x24uIMrQ/8lngbtaValOxa/VW01Za7ks9swK/ NNLg== 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=AyvUKwoNoQhgHhZ2GYcl30mAfoUN7hvmsfOCJWBfsqQ=; b=cb48u3qbifCMRbf5YlebzpA6WVoQKlG1W3i096dntPl4AYHatBUg1IHEeJZaDdmIDl 8S756fW1IrvOeayjhX2PAGDaqnDNvPM9OxcGXewKgJvTh/8T9gpCRiCgQEi8QcK7kU5S 2ZG287EprTVU/jwOTTmYOuD4FixH7tGO0mB8PTz+ys5elX+w7uaBU/1PIxgAmW2NE9EG iZsCCUScm1FxSjZvUzepYpvkgzxJTb9bB5LSJygAZnnyJllaM923OGWcT3iKWmhXfAVW Jdb3mbi4FdaLyaDYDjiuZGW5op9QnFZxwDOfaU6xQGhMDpoOWRs5BRziNR8JJl1aIgbx pnsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=Q/IPE7LT; 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 w61si5609779plb.401.2017.07.04.08.43.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jul 2017 08:43:40 -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=Q/IPE7LT; 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 473B320945609; Tue, 4 Jul 2017 08:42:01 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pg0-x231.google.com (mail-pg0-x231.google.com [IPv6:2607:f8b0:400e:c05::231]) (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 EFC71209455F8 for ; Tue, 4 Jul 2017 08:41:59 -0700 (PDT) Received: by mail-pg0-x231.google.com with SMTP id j186so111770483pge.2 for ; Tue, 04 Jul 2017 08:43:38 -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=dz/rz1aUUgraXmWUvmp8ydgjOTESZCBjSov2Jsc4Glg=; b=Q/IPE7LT+WicT03De2KDI/EziESEe8O6puEg0cuw+epBbWPn2+e+It05hlLUwFmFCc sjdDfxr0G1RtuN6NACrMgW22rkxYnZbjYJBSrnanNKQo4owM1bac97jSPY6Ck62bM6lX A2GNQQSg8ShmaH4YkgwnHEQ1DbcpX41xr6gFM= 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=dz/rz1aUUgraXmWUvmp8ydgjOTESZCBjSov2Jsc4Glg=; b=SLnBn42FeQgi8PrHtGkGzqWpQqJ1PY6wC1jQEiBzeo/eSycBwUfCglBP9hFEZW2ObN 7eFHJ7XX8+zkGWeyuYXlgbCOYsrd9/0fHFP/pn2ltjdZZVOALuXchYQb/gtLKTKE1vjx 8YdrHgY2NVfMokkhYHhFrn8JXndhIeXVExS2aisethsPkJMg36QpOmPD/8uzl8m0JFnD /O2Jk6wiDcTWAdvK6YSc2vL8ZMvz8iJswzu7Q1IJ1AS21CnZej/CRwexVzhA+kRi27B9 Ee6yaCUYcCXy4n9HAyPnP2lOc8CRtyKXsUdKjEizo17knU764vR5F3oZ3wrxPjMb0iBo MEuw== X-Gm-Message-State: AIVw113TGDse7jQdUphZiFFPGTfmcCyPB4sBiQ278CWLG21QMWWcmtIC B6qCoeDC5KEkSr2c X-Received: by 10.84.238.133 with SMTP id v5mr17503065plk.162.1499183018100; Tue, 04 Jul 2017 08:43:38 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.78]) by smtp.gmail.com with ESMTPSA id w20sm9227877pgc.34.2017.07.04.08.43.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Jul 2017 08:43:37 -0700 (PDT) From: Jun Nie To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, haojian.zhuang@linaro.org, edk2-devel@lists.01.org Date: Tue, 4 Jul 2017 23:43:16 +0800 Message-Id: <1499182996-16225-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v5] 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.c | 3 +++ EmbeddedPkg/Universal/MmcDxe/Mmc.h | 2 +- EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.c b/EmbeddedPkg/Universal/MmcDxe/Mmc.c index 30268e3..ce27150 100644 --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.c +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.c @@ -177,6 +177,9 @@ EFI_STATUS DestroyMmcHostInstance ( if (MmcHostInstance->BlockIo.Media) { FreePool(MmcHostInstance->BlockIo.Media); } + if (MmcHostInstance->CardInfo.ECSDData) { + FreePages (MmcHostInstance->CardInfo.ECSDData, EFI_SIZE_TO_PAGES (sizeof (ECSD))); + } FreePool (MmcHostInstance); return Status; diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h b/EmbeddedPkg/Universal/MmcDxe/Mmc.h index b7b9454..eb4652b 100644 --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h @@ -320,7 +320,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;