From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::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 4990021CF3B93 for ; Mon, 3 Jul 2017 09:44:22 -0700 (PDT) Received: by mail-wm0-x230.google.com with SMTP id f67so60768959wmh.1 for ; Mon, 03 Jul 2017 09:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=y6aorAoxqgQSCHoOBy0XTZSG8D3ITM2OnouvGISpMQA=; b=HEwOh/bdc0zISAl344irIEOkMRI3Lop6JeUVmF0y0kXqMHpWqLXhITg4zMuzXbLWIy FRzr8nVBPGMzHsiCBY3RT7wdqaDPMja5Y02ZnC+Plxt09/LLCv07rv/JhuUzzcVbzXaM zBVJxpQTplKxZ6XYexjDnNsR3sxEZ4ZQwV9SM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=y6aorAoxqgQSCHoOBy0XTZSG8D3ITM2OnouvGISpMQA=; b=rcMPjgzmyEmjZj0cUFRyv38g06c1I+wJOA+dD5QZDAK97vQEz8gzUPqNXw6+EecNHx MtP3zhImoCBwQemBP5vsg2IXzj4F0fKQuUbUeyKPwDVsOAFMusimLrVSjlsCpuwzcx0t C/kxcFDi2rmhHTIcwKCaXsOdVdqrawgGmSGi2wh9skBli4YzdGZOMmyP04bWGl+sAL+y Xss6hlUACtiF3L0S7znRIxI7kEt/SvXWe76V0LsYjS2zevk914VQdT1jVYmeG3PZXp2k PvDzi5qaxxJo3Sa12gGDBVchcptA24bXq80afzLh84Bb7AHO8JwpR15c2jLTQ8cvbf+9 eIqg== X-Gm-Message-State: AIVw111ISOzGk9bB6ORtsZEIUBzgctwzJvAHj50GXdeGRsgKQ3QvZbse mRd5ZEb1PRV8swtl X-Received: by 10.28.218.145 with SMTP id r139mr16270806wmg.69.1499100358154; Mon, 03 Jul 2017 09:45:58 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id a3sm19933848wra.17.2017.07.03.09.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 09:45:57 -0700 (PDT) Date: Mon, 3 Jul 2017 17:45:56 +0100 From: Leif Lindholm To: Jun Nie Cc: ard.biesheuvel@linaro.org, haojian.zhuang@linaro.org, edk2-devel@lists.01.org, shawn.guo@linaro.org, jason.liu@linaro.org Message-ID: <20170703164556.GJ26676@bivouac.eciton.net> References: <1498790580-11893-1-git-send-email-jun.nie@linaro.org> MIME-Version: 1.0 In-Reply-To: <1498790580-11893-1-git-send-email-jun.nie@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [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: , X-List-Received-Date: Mon, 03 Jul 2017 16:44:22 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jun 30, 2017 at 10:43:00AM +0800, Jun Nie wrote: > 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(-) > > 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))); So, this memory is now being freed when the operation fails. But it also needs to be cleaned up when the host is deleted. I suggested adding the free operation to DestroyMmcHostInstance. / Leif > + 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; > > -- > 1.9.1 >