From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=216.228.121.65; helo=hqemgate16.nvidia.com; envelope-from=ashishsingha@nvidia.com; receiver=edk2-devel@lists.01.org Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A9FA22119BBDE for ; Tue, 18 Dec 2018 13:28:40 -0800 (PST) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 18 Dec 2018 13:28:30 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 18 Dec 2018 13:28:39 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 18 Dec 2018 13:28:39 -0800 Received: from HQMAIL112.nvidia.com (172.18.146.18) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 18 Dec 2018 21:28:39 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL112.nvidia.com (172.18.146.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 18 Dec 2018 21:28:38 +0000 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.54) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Tue, 18 Dec 2018 21:28:38 +0000 Received: from BYAPR12MB2743.namprd12.prod.outlook.com (20.177.125.220) by BYAPR12MB2600.namprd12.prod.outlook.com (20.176.255.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Tue, 18 Dec 2018 21:28:36 +0000 Received: from BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::48d0:7a19:5dfb:fae2]) by BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::48d0:7a19:5dfb:fae2%5]) with mapi id 15.20.1425.021; Tue, 18 Dec 2018 21:28:36 +0000 From: Ashish Singhal To: "Wu, Hao A" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH v6 2/2] MdeModulePkg/SdMmcPciHcDxe: Add SDMMC HC v4 and above Support. Thread-Index: AQHUiIM9nBwQNRhte0yq35mfe/+F4KWFHvbV Date: Tue, 18 Dec 2018 21:28:36 +0000 Message-ID: References: <813fddd12ccfd0a0958930438d5827c221aeafea.1543515597.git.ashishsingha@nvidia.com> <7213b761dc6c09d587e63823c5241a54aa1b0e6f.1543515597.git.ashishsingha@nvidia.com>, In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ashishsingha@nvidia.com; x-originating-ip: [216.228.112.22] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BYAPR12MB2600; 6:Xeka6+9FfA7SJeWvR74agM5WIQZHfTwcljnwDFd/rh5fluTfC5lesU6ihculJdJX27zP5pbXVzCdMLzocoOTHY/JXIyGsfZI0U5Y2fwrBRBK0JyFYZO1kFcbBrn2+WpdN6bZ1DcNuDkmwZ4hK1wTjH7sA+cOiYLYfRRGETyQumuJffU+vbHFFQ5+bVBUHiFWZPUhHyc/etSbM/aWKrQswz3SaW/e7+LFeWKZ1RmdLK05oGxpEm6yJikXEbWn/xa2PpSUu+BVu6faNTu0HywQ2yXZO1xLIU09mEZjwptBAzVNefJcdTswx1oivC/6K56DfMGH968BsmYb2Y8e4E4CkrSipptF08xnBooGNdqYoCjWKrT//nSbM4yf26repfWGyNqwgKVqXWC328Tug+dzrxyMZ6vvTuEWmZnVm73gVR+GAQBBoO2v0xkxig2Od3BCvxys6nKhGcN0K080K/iF3A==; 5:b9pTEy8+W7fqqLsF3/+tmRNW/T1L5h4L5QzMXoih46aDM/5kBj3bd3/ItTWm2TEQd3mNJNpL56awpTGPLYEjEqmOS6uQKmF9pd0w3XU54pDuFL8MdFqR0f4x3i1F9cv92yV7ZzfzB25QDX1zKTlbiZlm6oigQj5eHHkYN0xqClY=; 7:SNAQvgZg8Mm0incEwpOnI3TuNbDiouAWrWo5QHTNpO5NTjciC1hOGU/QW4eBkvkmd9aqWkPmOwyqYMo3A9nq/5yxqK0vcpkBPL/PuHR3P9CuMrmZHNk3wNkj1Holl3qU1c3m9xXIx1gXheMkftOkZw== x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 0bc2e010-0df6-43d7-9a2b-08d6652fc520 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BYAPR12MB2600; x-ms-traffictypediagnostic: BYAPR12MB2600: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(3231475)(944501520)(52105112)(93006095)(93001095)(3002001)(10201501046)(148016)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:BYAPR12MB2600; BCL:0; PCL:0; RULEID:; SRVR:BYAPR12MB2600; x-forefront-prvs: 08902E536D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6029001)(366004)(376002)(346002)(396003)(39860400002)(136003)(13464003)(189003)(199004)(51874003)(86362001)(236005)(446003)(53936002)(486006)(2501003)(19627405001)(6116002)(6306002)(4744004)(53946003)(606006)(3846002)(25786009)(54896002)(6246003)(71190400001)(55016002)(97736004)(106356001)(71200400001)(68736007)(316002)(110136005)(9686003)(105586002)(966005)(478600001)(19627235002)(186003)(14454004)(229853002)(14444005)(2906002)(8936002)(81156014)(6436002)(8676002)(6606003)(26005)(66066001)(7696005)(7736002)(53546011)(6506007)(74316002)(99286004)(5660300001)(76176011)(476003)(81166006)(33656002)(11346002)(102836004)(256004)(559001)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR12MB2600; H:BYAPR12MB2743.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nvidia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: C6rLEAicvlQDky6WVEdtIgUUt1sEe3f4ed+adUFhytEx9ElYC6oVG3Q7q9COiqm1kET3tnj+aCrzO3NRLo8OX9bmJES4HZL/qpCH9ph+800e9UsO4PM536EGUpedF3PR9wf72ifgJ6nwMx0Djd1acv19lva86MoTxzqTkjBV9P09k7QWBztWGTYb2bBvwxL3vDjSvnWEAj2FTARIUnBeysIVKuZPxBF00LPZTgBqL0330CelOwAJpn8VRFL2xBWOoE2chdz0JvPg9nhFZT5v8EN8NnqvLUc+C4qfM3MNrl9/u0c74A8e0i2vjxoWHToz spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0bc2e010-0df6-43d7-9a2b-08d6652fc520 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Dec 2018 21:28:36.3319 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2600 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1545168511; bh=wzqoqUOAVuU3GJ8fWCOYarPedu75vWyKLpjcJthixkg=; h=X-PGP-Universal:From:To:Subject:Thread-Topic:Thread-Index:Date: Message-ID:References:In-Reply-To:Accept-Language:X-MS-Has-Attach: X-MS-TNEF-Correlator:authentication-results:x-originating-ip: x-ms-publictraffictype:x-microsoft-exchange-diagnostics: x-ms-exchange-antispam-srfa-diagnostics: x-ms-office365-filtering-correlation-id:x-microsoft-antispam: x-ms-traffictypediagnostic:x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck:x-exchange-antispam-report-cfa-test: x-forefront-prvs:x-forefront-antispam-report:received-spf: x-microsoft-antispam-message-info:spamdiagnosticoutput: spamdiagnosticmetadata:MIME-Version: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-originalarrivaltime: X-MS-Exchange-CrossTenant-fromentityheader: X-MS-Exchange-CrossTenant-id: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg: Content-Language:Content-Type; b=Hjt1YH7Hc8FrFXGLdjBhCH88Z1rQWtTO+EM3EIcfZR7hZxQXNq3sJYkdM/JbsDzli PZe1iuSpxBQxxuUDKwIXlYoC3jKMNm0/W1j2YLkhntpVAFmb0vrHr6iAUdUBOy9k18 B+BJ3dhMERINVPMecEO0YixKm+nI1sJffddcJAXAaGj/DSzKBda5CIZcN8EbCVbExD swDAx9g8XNoyI8IzK1PR7pQ8kacxKO/bqlBIA1TF+tXysYfSRbcfDOXUJ3xgh91gLv 8m97KUhKzX2GKb5qiQCK8MQj8inN92xmo3PEXeF7io2hgU8dLbb7jJJCE3+h3eCv/O bKeafkeE0uwmA== X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [PATCH v6 2/2] MdeModulePkg/SdMmcPciHcDxe: Add SDMMC HC v4 and above Support. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2018 21:28:40 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello Hao, I have made all the changes as recommended and have submitted patch v7. I= =20have completed all verification as suggested by you and it all seems t= o be working. I have also made changes for passing controller version thr= ough private structure. Thanks Ashish ________________________________ From: Wu, Hao A Sent: Friday, November 30, 2018 1:03:15 AM To: Ashish Singhal; edk2-devel@lists.01.org Subject: RE: [edk2] [PATCH v6 2/2] MdeModulePkg/SdMmcPciHcDxe: Add SDMMC = HC v4 and above Support. Hello, Please refer to the inline comments below: > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Ashish Singhal > Sent: Friday, November 30, 2018 3:15 AM > To: edk2-devel@lists.01.org > Cc: Ashish Singhal > Subject: [edk2] [PATCH v6 2/2] MdeModulePkg/SdMmcPciHcDxe: Add > SDMMC HC v4 and above Support. > > Add SDMA, ADMA2 and 26b data length support. > > If V4 64 bit address mode is enabled in compatibility register, > program controller to enable V4 host mode and use appropriate > SDMA registers supporting 64 bit addresses. > > If V4 64 bit address mode is enabled in compatibility register, > program controller to enable V4 host mode and use appropriate > ADMA descriptors supporting 64 bit addresses. > > If host controller version is above V4.0, enable ADMA2 with 26b data > length support for better performance. HC 2 register is configured to > use 26 bit data lengths and ADMA2 descriptors are configured appropriat= ely. > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1359 > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ashish Singhal > --- > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 4 +- > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 328 > ++++++++++++++++++--- > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h | 48 ++- > 3 files changed, 322 insertions(+), 58 deletions(-) > > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h > index 8c1a589..3af7c95 100644 > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h > @@ -2,6 +2,7 @@ > > Provides some data structure definitions used by the SD/MMC host > controller driver. > > +Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. > Copyright (c) 2015, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > @@ -150,7 +151,8 @@ typedef struct { > BOOLEAN Started; > UINT64 Timeout; > > - SD_MMC_HC_ADMA_DESC_LINE *AdmaDesc; > + SD_MMC_HC_ADMA_32_DESC_LINE *Adma32Desc; > + SD_MMC_HC_ADMA_64_DESC_LINE *Adma64Desc; > EFI_PHYSICAL_ADDRESS AdmaDescPhy; > VOID *AdmaMap; > UINT32 AdmaPages; > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c > index 598b6a3..debc3be 100644 > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c > @@ -4,6 +4,7 @@ > > It would expose EFI_SD_MMC_PASS_THRU_PROTOCOL for upper layer use. > > + Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. > Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of th= e > BSD License > @@ -418,6 +419,36 @@ SdMmcHcWaitMmioSet ( > } > > /** > + Get the controller version information from the specified slot. > + > + @param[in] PciIo The PCI IO protocol instance. > + @param[in] Slot The slot number of the SD card to send t= he > command to. > + @param[out] Version The buffer to store the version informat= ion. > + > + @retval EFI_SUCCESS The operation executes successfully. > + @retval Others The operation fails. > + > +**/ > +EFI_STATUS > +SdMmcHcGetControllerVersion ( > + IN EFI_PCI_IO_PROTOCOL *PciIo, > + IN UINT8 Slot, > + OUT UINT16 *Version > + ) > +{ > + EFI_STATUS Status; > + > + Status =3D SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, > sizeof (UINT16), Version); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + *Version &=3D 0xFF; > + > + return EFI_SUCCESS; > +} > + > +/** > Software reset the specified SD/MMC host controller and enable all > interrupts. > > @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA > instance. > @@ -776,18 +807,19 @@ SdMmcHcClockSupply ( > > DEBUG ((DEBUG_INFO, "BaseClkFreq %dMHz Divisor %d > ClockFreq %dKhz\n", BaseClkFreq, Divisor, ClockFreq)); > > - Status =3D SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, > sizeof (ControllerVer), &ControllerVer); > + Status =3D SdMmcHcGetControllerVersion (PciIo, Slot, &ControllerVer)= ; > if (EFI_ERROR (Status)) { > return Status; > } > // > // Set SDCLK Frequency Select and Internal Clock Enable fields in Cl= ock > Control register. > // > - if (((ControllerVer & 0xFF) >=3D SD_MMC_HC_CTRL_VER_300) && > - ((ControllerVer & 0xFF) <=3D SD_MMC_HC_CTRL_VER_420)) { > + if ((ControllerVer >=3D SD_MMC_HC_CTRL_VER_300) && > + (ControllerVer <=3D SD_MMC_HC_CTRL_VER_420)) { > ASSERT (Divisor <=3D 0x3FF); > ClockCtrl =3D ((Divisor & 0xFF) << 8) | ((Divisor & 0x300) >> 2); > - } else if (((ControllerVer & 0xFF) =3D=3D 0) || ((ControllerVer & 0x= FF) =3D=3D 1)) { > + } else if ((ControllerVer =3D=3D SD_MMC_HC_CTRL_VER_100) || > + (ControllerVer =3D=3D SD_MMC_HC_CTRL_VER_200)) { > // > // Only the most significant bit can be used as divisor. > // > @@ -935,6 +967,60 @@ SdMmcHcSetBusWidth ( > } > > /** > + Configure V4 controller enhancements at initialization. > + > + @param[in] PciIo The PCI IO protocol instance. > + @param[in] Slot The slot number of the SD card to send the= > command to. > + @param[in] Capability The capability of the slot. > + > + @retval EFI_SUCCESS The clock is supplied successfully. > + > +**/ > +EFI_STATUS > +SdMmcHcInitV4Enhancements ( > + IN EFI_PCI_IO_PROTOCOL *PciIo, > + IN UINT8 Slot, > + IN SD_MMC_HC_SLOT_CAP Capability > + ) > +{ > + EFI_STATUS Status; > + UINT16 ControllerVer; > + UINT16 HostCtrl2; > + > + // > + // Check if controller version V4 or higher > + // > + Status =3D SdMmcHcGetControllerVersion (PciIo, Slot, &ControllerVer)= ; > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_400) { > + HostCtrl2 =3D SD_MMC_HC_V4_EN; > + // > + // Check if V4 64bit support is available > + // > + if (Capability.SysBus64V4 !=3D 0) { > + HostCtrl2 |=3D SD_MMC_HC_64_ADDR_EN; > + DEBUG ((DEBUG_INFO, "Enabled V4 64 bit system bus support\n")); > + } > + // > + // Check if controller version V4.10 or higher > + // > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_410) { > + HostCtrl2 |=3D SD_MMC_HC_26_DATA_LEN_ADMA_EN; > + DEBUG ((DEBUG_INFO, "Enabled V4 26 bit data length ADMA > support\n")); > + } > + Status =3D SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeo= f > (HostCtrl2), &HostCtrl2); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + } > + > + return EFI_SUCCESS; > +} > + > +/** > Supply SD/MMC card with lowest clock frequency at initialization. > > @param[in] PciIo The PCI IO protocol instance. > @@ -1105,6 +1191,11 @@ SdMmcHcInitHost ( > PciIo =3D Private->PciIo; > Capability =3D Private->Capability[Slot]; > > + Status =3D SdMmcHcInitV4Enhancements (PciIo, Slot, Capability); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > Status =3D SdMmcHcInitClockFreq (PciIo, Slot, Private->BaseClkFreq[S= lot]); > if (EFI_ERROR (Status)) { > return Status; > @@ -1263,7 +1354,7 @@ SdMmcHcLedOnOff ( > /** > Build ADMA descriptor table for transfer. > > - Refer to SD Host Controller Simplified spec 3.0 Section 1.13 for det= ails. > + Refer to SD Host Controller Simplified spec 4.2 Section 1.13 for det= ails. > > @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.= > > @@ -1281,49 +1372,98 @@ BuildAdmaDescTable ( > UINT64 Entries; > UINT32 Index; > UINT64 Remaining; > - UINT32 Address; > + UINT64 Address; > UINTN TableSize; > EFI_PCI_IO_PROTOCOL *PciIo; > EFI_STATUS Status; > UINTN Bytes; > + UINT16 ControllerVer; > + BOOLEAN AddressingMode64; > + BOOLEAN DataLength26; > + UINT32 AdmaMaxDataPerLine; > + UINT32 DescSize; > + VOID *AdmaDesc; > + > + AddressingMode64 =3D FALSE; > + DataLength26 =3D FALSE; > + AdmaMaxDataPerLine =3D ADMA_MAX_DATA_PER_LINE_16B; > + DescSize =3D sizeof (SD_MMC_HC_ADMA_32_DESC_LINE); > + AdmaDesc =3D NULL; > > Data =3D Trb->DataPhy; > DataLen =3D Trb->DataLen; > PciIo =3D Trb->Private->PciIo; > + > + // > + // Detect whether 64bit addressing is supported. > + // > + Status =3D SdMmcHcGetControllerVersion (PciIo, Trb->Slot, &Controlle= rVer); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_400) { > + Status =3D SdMmcHcCheckMmioSet(PciIo, Trb->Slot, > SD_MMC_HC_HOST_CTRL2, 0x2, > + SD_MMC_HC_V4_EN|SD_MMC_HC_64_ADDR_EN,= > SD_MMC_HC_V4_EN|SD_MMC_HC_64_ADDR_EN); > + if (!EFI_ERROR (Status)) { > + AddressingMode64 =3D TRUE; > + DescSize =3D sizeof (SD_MMC_HC_ADMA_64_DESC_LINE); > + } > + } > // > - // Only support 32bit ADMA Descriptor Table > + // Check for valid ranges in 32bit ADMA Descriptor Table > // > - if ((Data >=3D 0x100000000ul) || ((Data + DataLen) > 0x100000000ul))= =20{ > + if (!AddressingMode64 && > + ((Data >=3D 0x100000000ul) || ((Data + DataLen) > 0x100000000ul)= )) { > return EFI_INVALID_PARAMETER; > } > // > - // Address field shall be set on 32-bit boundary (Lower 2-bit is alw= ays set > to 0) > - // for 32-bit address descriptor table. > + // Check address field alignment > + // > + if (AddressingMode64) { > + // > + // Address field shall be set on 32-bit boundary (Lower 2-bit is a= lways set > to 0) Please update the comments here. The boundary is 64-bit with lower 3-bit cleared. > + // > + if ((Data & (BIT0 | BIT1 | BIT2)) !=3D 0) { > + DEBUG ((DEBUG_INFO, "The buffer [0x%x] to construct ADMA desc is= =20not > aligned to 8 bytes boundary!\n", Data)); > + } > + } else { > + // > + // Address field shall be set on 32-bit boundary (Lower 2-bit is a= lways set > to 0) > + // > + if ((Data & (BIT0 | BIT1)) !=3D 0) { > + DEBUG ((DEBUG_INFO, "The buffer [0x%x] to construct ADMA desc is= =20not > aligned to 4 bytes boundary!\n", Data)); > + } > + } > + // > + // Detect whether 26bit data length is supported. > // > - if ((Data & (BIT0 | BIT1)) !=3D 0) { > - DEBUG ((DEBUG_INFO, "The buffer [0x%x] to construct ADMA desc is n= ot > aligned to 4 bytes boundary!\n", Data)); > + Status =3D SdMmcHcCheckMmioSet(PciIo, Trb->Slot, > SD_MMC_HC_HOST_CTRL2, 0x2, > + SD_MMC_HC_26_DATA_LEN_ADMA_EN, > SD_MMC_HC_26_DATA_LEN_ADMA_EN); > + if (!EFI_ERROR (Status)) { > + DataLength26 =3D TRUE; > + AdmaMaxDataPerLine =3D ADMA_MAX_DATA_PER_LINE_26B; > } > > - Entries =3D DivU64x32 ((DataLen + ADMA_MAX_DATA_PER_LINE - 1), > ADMA_MAX_DATA_PER_LINE); > - TableSize =3D (UINTN)MultU64x32 (Entries, sizeof > (SD_MMC_HC_ADMA_DESC_LINE)); > + Entries =3D DivU64x32 ((DataLen + AdmaMaxDataPerLine - 1), > AdmaMaxDataPerLine); > + TableSize =3D (UINTN)MultU64x32 (Entries, DescSize); > Trb->AdmaPages =3D (UINT32)EFI_SIZE_TO_PAGES (TableSize); > Status =3D PciIo->AllocateBuffer ( > PciIo, > AllocateAnyPages, > EfiBootServicesData, > EFI_SIZE_TO_PAGES (TableSize), > - (VOID **)&Trb->AdmaDesc, > + (VOID **)&AdmaDesc, > 0 > ); > if (EFI_ERROR (Status)) { > return EFI_OUT_OF_RESOURCES; > } > - ZeroMem (Trb->AdmaDesc, TableSize); > + ZeroMem (AdmaDesc, TableSize); > Bytes =3D TableSize; > Status =3D PciIo->Map ( > PciIo, > EfiPciIoOperationBusMasterCommonBuffer, > - Trb->AdmaDesc, > + AdmaDesc, > &Bytes, > &Trb->AdmaDescPhy, > &Trb->AdmaMap > @@ -1336,12 +1476,13 @@ BuildAdmaDescTable ( > PciIo->FreeBuffer ( > PciIo, > EFI_SIZE_TO_PAGES (TableSize), > - Trb->AdmaDesc > + AdmaDesc > ); > return EFI_OUT_OF_RESOURCES; > } > > - if ((UINT64)(UINTN)Trb->AdmaDescPhy > 0x100000000ul) { > + if ((!AddressingMode64) && > + (UINT64)(UINTN)Trb->AdmaDescPhy > 0x100000000ul) { > // > // The ADMA doesn't support 64bit addressing. > // > @@ -1352,35 +1493,71 @@ BuildAdmaDescTable ( > PciIo->FreeBuffer ( > PciIo, > EFI_SIZE_TO_PAGES (TableSize), > - Trb->AdmaDesc > + AdmaDesc > ); > return EFI_DEVICE_ERROR; > } > > Remaining =3D DataLen; > - Address =3D (UINT32)Data; > + Address =3D Data; > + if (!AddressingMode64) { > + Trb->Adma32Desc =3D AdmaDesc; > + Trb->Adma64Desc =3D NULL; > + } else { > + Trb->Adma64Desc =3D AdmaDesc; > + Trb->Adma32Desc =3D NULL; > + } > for (Index =3D 0; Index < Entries; Index++) { > - if (Remaining <=3D ADMA_MAX_DATA_PER_LINE) { > - Trb->AdmaDesc[Index].Valid =3D 1; > - Trb->AdmaDesc[Index].Act =3D 2; > - Trb->AdmaDesc[Index].Length =3D (UINT16)Remaining; > - Trb->AdmaDesc[Index].Address =3D Address; > - break; > + if (!AddressingMode64) { > + if (Remaining < AdmaMaxDataPerLine) { For the file access issue on SD/eMMC devices, found that it is related wi= th the above change. Please update it to: if (Remaining <=3D AdmaMaxDataPerLine) { Otherwise, when the length of the last chunk of transfer equals to 'AdmaMaxDataPerLine', the proposed change will not break out of the 'for'= =20loop. This will lead to a value underflow of the variable 'Remaining', which wi= ll further cause the file access failure. > + Trb->Adma32Desc[Index].Valid =3D 1; > + Trb->Adma32Desc[Index].Act =3D 2; > + if (DataLength26 =3D=3D TRUE) { Please update the above line to: if (DataLength26) { There are some similar cases below, please help to update them as well. > + Trb->Adma32Desc[Index].UpperLength =3D (UINT32)(Remaining >>= =2016); > + } > + Trb->Adma32Desc[Index].LowerLength =3D (UINT32)(Remaining & > MAX_UINT16); The above 2 statements seem not consistent with their counterparts under = the 'else' part. Please help to refine one of them, thanks. > + Trb->Adma32Desc[Index].Address =3D (UINT32)Address; > + break; > + } else { > + Trb->Adma32Desc[Index].Valid =3D 1; > + Trb->Adma32Desc[Index].Act =3D 2; > + if (DataLength26 =3D=3D TRUE) { > + Trb->Adma32Desc[Index].UpperLength =3D 0; > + } > + Trb->Adma32Desc[Index].LowerLength =3D 0; > + Trb->Adma32Desc[Index].Address =3D (UINT32)Address; > + } > } else { > - Trb->AdmaDesc[Index].Valid =3D 1; > - Trb->AdmaDesc[Index].Act =3D 2; > - Trb->AdmaDesc[Index].Length =3D 0; > - Trb->AdmaDesc[Index].Address =3D Address; > + if (Remaining < AdmaMaxDataPerLine) { Same issue with the previous one. Could you please help to verify on SD controllers with version greater th= an 4.0, with the case that the data length of a TRB is a multiple of 64M byt= es? Thanks in advance. Best Regards, Hao Wu > + Trb->Adma64Desc[Index].Valid =3D 1; > + Trb->Adma64Desc[Index].Act =3D 2; > + if (DataLength26 =3D=3D TRUE) { > + Trb->Adma64Desc[Index].UpperLength =3D (UINT16)(Remaining >= > 16); > + } > + Trb->Adma64Desc[Index].LowerLength =3D (UINT16)(Remaining & > MAX_UINT16); > + Trb->Adma64Desc[Index].LowerAddress =3D (UINT32)Address; > + Trb->Adma64Desc[Index].UpperAddress =3D (UINT32)(Address >> 32= ); > + break; > + } else { > + Trb->Adma64Desc[Index].Valid =3D 1; > + Trb->Adma64Desc[Index].Act =3D 2; > + if (DataLength26 =3D=3D TRUE) { > + Trb->Adma64Desc[Index].UpperLength =3D 0; > + } > + Trb->Adma64Desc[Index].LowerLength =3D 0; > + Trb->Adma64Desc[Index].LowerAddress =3D (UINT32)Address; > + Trb->Adma64Desc[Index].UpperAddress =3D (UINT32)(Address >> 32= ); > + } > } > > - Remaining -=3D ADMA_MAX_DATA_PER_LINE; > - Address +=3D ADMA_MAX_DATA_PER_LINE; > + Remaining -=3D AdmaMaxDataPerLine; > + Address +=3D AdmaMaxDataPerLine; > } > > // > // Set the last descriptor line as end of descriptor table > // > - Trb->AdmaDesc[Index].End =3D 1; > + AddressingMode64 ? (Trb->Adma64Desc[Index].End =3D 1) : (Trb- > >Adma32Desc[Index].End =3D 1); > return EFI_SUCCESS; > } > > @@ -1524,11 +1701,18 @@ SdMmcFreeTrb ( > Trb->AdmaMap > ); > } > - if (Trb->AdmaDesc !=3D NULL) { > + if (Trb->Adma32Desc !=3D NULL) { > PciIo->FreeBuffer ( > PciIo, > Trb->AdmaPages, > - Trb->AdmaDesc > + Trb->Adma32Desc > + ); > + } > + if (Trb->Adma64Desc !=3D NULL) { > + PciIo->FreeBuffer ( > + PciIo, > + Trb->AdmaPages, > + Trb->Adma64Desc > ); > } > if (Trb->DataMap !=3D NULL) { > @@ -1668,12 +1852,16 @@ SdMmcExecTrb ( > UINT16 Cmd; > UINT16 IntStatus; > UINT32 Argument; > - UINT16 BlkCount; > + UINT32 BlkCount; > UINT16 BlkSize; > UINT16 TransMode; > UINT8 HostCtrl1; > - UINT32 SdmaAddr; > + UINT64 SdmaAddr; > UINT64 AdmaAddr; > + UINT16 ControllerVer; > + BOOLEAN AddressingMode64; > + > + AddressingMode64 =3D FALSE; > > Packet =3D Trb->Packet; > PciIo =3D Trb->Private->PciIo; > @@ -1706,13 +1894,32 @@ SdMmcExecTrb ( > > SdMmcHcLedOnOff (PciIo, Trb->Slot, TRUE); > > + Status =3D SdMmcHcGetControllerVersion (PciIo, Trb->Slot, &Controlle= rVer); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_400) { > + Status =3D SdMmcHcCheckMmioSet(PciIo, Trb->Slot, > SD_MMC_HC_HOST_CTRL2, 0x2, > + SD_MMC_HC_V4_EN|SD_MMC_HC_64_ADDR_EN,= > SD_MMC_HC_V4_EN|SD_MMC_HC_64_ADDR_EN); > + if (!EFI_ERROR (Status)) { > + AddressingMode64 =3D TRUE; > + } > + } > + > if (Trb->Mode =3D=3D SdMmcSdmaMode) { > - if ((UINT64)(UINTN)Trb->DataPhy >=3D 0x100000000ul) { > + if ((!AddressingMode64) && > + ((UINT64)(UINTN)Trb->DataPhy >=3D 0x100000000ul)) { > return EFI_INVALID_PARAMETER; > } > > - SdmaAddr =3D (UINT32)(UINTN)Trb->DataPhy; > - Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_SDMA_ADDR,= > FALSE, sizeof (SdmaAddr), &SdmaAddr); > + SdmaAddr =3D (UINT64)(UINTN)Trb->DataPhy; > + > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_400) { > + Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, > SD_MMC_HC_ADMA_SYS_ADDR, FALSE, sizeof (UINT64), &SdmaAddr); > + } else { > + Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_SDMA_ADDR,= > FALSE, sizeof (UINT32), &SdmaAddr); > + } > + > if (EFI_ERROR (Status)) { > return Status; > } > @@ -1742,9 +1949,13 @@ SdMmcExecTrb ( > // > // Calcuate Block Count. > // > - BlkCount =3D (UINT16)(Trb->DataLen / Trb->BlockSize); > + BlkCount =3D (Trb->DataLen / Trb->BlockSize); > + } > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_410) { > + Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_SDMA_ADDR, > FALSE, sizeof (UINT32), &BlkCount); > + } else { > + Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_BLK_COUNT, > FALSE, sizeof (UINT16), &BlkCount); > } > - Status =3D SdMmcHcRwMmio (PciIo, Trb->Slot, SD_MMC_HC_BLK_COUNT, > FALSE, sizeof (BlkCount), &BlkCount); > if (EFI_ERROR (Status)) { > return Status; > } > @@ -1840,10 +2051,11 @@ SdMmcCheckTrbResult ( > EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet; > UINT16 IntStatus; > UINT32 Response[4]; > - UINT32 SdmaAddr; > + UINT64 SdmaAddr; > UINT8 Index; > UINT8 SwReset; > UINT32 PioLength; > + UINT16 ControllerVer; > > SwReset =3D 0; > Packet =3D Trb->Packet; > @@ -1964,8 +2176,28 @@ SdMmcCheckTrbResult ( > // > // Update SDMA Address register. > // > - SdmaAddr =3D SD_MMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->DataPhy, > SD_MMC_SDMA_BOUNDARY); > - Status =3D SdMmcHcRwMmio ( > + SdmaAddr =3D SD_MMC_SDMA_ROUND_UP ((UINTN)Trb->DataPhy, > SD_MMC_SDMA_BOUNDARY); > + > + Status =3D SdMmcHcGetControllerVersion ( > + Private->PciIo, > + Trb->Slot, > + &ControllerVer > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + if (ControllerVer >=3D SD_MMC_HC_CTRL_VER_400) { > + Status =3D SdMmcHcRwMmio ( > + Private->PciIo, > + Trb->Slot, > + SD_MMC_HC_ADMA_SYS_ADDR, > + FALSE, > + sizeof (UINT64), > + &SdmaAddr > + ); > + } else { > + Status =3D SdMmcHcRwMmio ( > Private->PciIo, > Trb->Slot, > SD_MMC_HC_SDMA_ADDR, > @@ -1973,10 +2205,12 @@ SdMmcCheckTrbResult ( > sizeof (UINT32), > &SdmaAddr > ); > + } > + > if (EFI_ERROR (Status)) { > goto Done; > } > - Trb->DataPhy =3D (UINT32)(UINTN)SdmaAddr; > + Trb->DataPhy =3D (UINT64)(UINTN)SdmaAddr; > } > > if ((Packet->SdMmcCmdBlk->CommandType !=3D SdMmcCommandTypeAdtc) > && > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h > index ad9ce64..230687b 100644 > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h > @@ -2,6 +2,7 @@ > > Provides some data structure definitions used by the SD/MMC host > controller driver. > > +Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. > Copyright (c) 2015, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > @@ -91,18 +92,38 @@ typedef enum { > // > // The maximum data length of each descriptor line > // > -#define ADMA_MAX_DATA_PER_LINE 0x10000 > +#define ADMA_MAX_DATA_PER_LINE_16B SIZE_64KB > +#define ADMA_MAX_DATA_PER_LINE_26B SIZE_64MB > > +// > +// ADMA descriptor for 32b addressing. > +// > typedef struct { > UINT32 Valid:1; > UINT32 End:1; > UINT32 Int:1; > UINT32 Reserved:1; > UINT32 Act:2; > - UINT32 Reserved1:10; > - UINT32 Length:16; > + UINT32 UpperLength:10; > + UINT32 LowerLength:16; > UINT32 Address; > -} SD_MMC_HC_ADMA_DESC_LINE; > +} SD_MMC_HC_ADMA_32_DESC_LINE; > + > +// > +// ADMA descriptor for 64b addressing. > +// > +typedef struct { > + UINT32 Valid:1; > + UINT32 End:1; > + UINT32 Int:1; > + UINT32 Reserved:1; > + UINT32 Act:2; > + UINT32 UpperLength:10; > + UINT32 LowerLength:16; > + UINT32 LowerAddress; > + UINT32 UpperAddress; > + UINT32 Reserved1; > +} SD_MMC_HC_ADMA_64_DESC_LINE; > > #define SD_MMC_SDMA_BOUNDARY 512 * 1024 > #define SD_MMC_SDMA_ROUND_UP(x, n) (((x) + n) & ~(n - 1)) > @@ -153,12 +174,19 @@ typedef struct { > // > // SD Host controller version > // > -#define SD_MMC_HC_CTRL_VER_100 0x00 > -#define SD_MMC_HC_CTRL_VER_200 0x01 > -#define SD_MMC_HC_CTRL_VER_300 0x02 > -#define SD_MMC_HC_CTRL_VER_400 0x03 > -#define SD_MMC_HC_CTRL_VER_410 0x04 > -#define SD_MMC_HC_CTRL_VER_420 0x05 > +#define SD_MMC_HC_CTRL_VER_100 0x00 > +#define SD_MMC_HC_CTRL_VER_200 0x01 > +#define SD_MMC_HC_CTRL_VER_300 0x02 > +#define SD_MMC_HC_CTRL_VER_400 0x03 > +#define SD_MMC_HC_CTRL_VER_410 0x04 > +#define SD_MMC_HC_CTRL_VER_420 0x05 > + > +// > +// SD Host controller V4 enhancements > +// > +#define SD_MMC_HC_V4_EN BIT12 > +#define SD_MMC_HC_64_ADDR_EN BIT13 > +#define SD_MMC_HC_26_DATA_LEN_ADMA_EN BIT10 > > /** > Dump the content of SD/MMC host controller's Capability Register. > -- > 2.7.4 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel -------------------------------------------------------------------------= ---------- This email message is for the sole use of the intended recipient(s) and m= ay contain confidential information. Any unauthorized review, use, disclosure or di= stribution is prohibited. If you are not the intended recipient, please contact the= =20sender by reply email and destroy all copies of the original message. -------------------------------------------------------------------------= ----------