From nobody Wed Dec 25 04:45:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1512145244894125.77684707453477; Fri, 1 Dec 2017 08:20:44 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 59C9E22183C9C; Fri, 1 Dec 2017 08:16:16 -0800 (PST) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0049.outbound.protection.outlook.com [104.47.37.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C374922183C83 for ; Fri, 1 Dec 2017 08:16:14 -0800 (PST) Received: from CY4PR03CA0093.namprd03.prod.outlook.com (10.171.242.162) by DM5PR03MB2698.namprd03.prod.outlook.com (10.168.197.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Fri, 1 Dec 2017 16:20:40 +0000 Received: from BN1AFFO11FD015.protection.gbl (2a01:111:f400:7c10::186) by CY4PR03CA0093.outlook.office365.com (2603:10b6:910:4d::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.282.5 via Frontend Transport; Fri, 1 Dec 2017 16:20:39 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD015.mail.protection.outlook.com (10.58.52.75) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.239.4 via Frontend Transport; Fri, 1 Dec 2017 16:20:39 +0000 Received: from uefi-OptiPlex-790.ap.freescale.net ([10.232.132.56]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id vB1GKSHd013131; Fri, 1 Dec 2017 09:20:36 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.37.49; helo=nam02-cy1-obe.outbound.protection.outlook.com; envelope-from=vabhav.sharma@nxp.com; receiver=edk2-devel@lists.01.org Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; From: Vabhav To: , , , Date: Fri, 1 Dec 2017 09:48:49 +0530 Message-ID: <1512101930-11887-3-git-send-email-vabhav.sharma@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512101930-11887-1-git-send-email-vabhav.sharma@nxp.com> References: <1512101930-11887-1-git-send-email-vabhav.sharma@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131566188397608192; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7966004)(336005)(39860400002)(376002)(39380400002)(346002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(8656006)(33646002)(47776003)(106466001)(36756003)(5660300001)(50226002)(77096006)(86362001)(68736007)(104016004)(2201001)(2950100002)(6666003)(76176011)(105606002)(51416003)(85426001)(8936002)(2906002)(16586007)(97736004)(48376002)(50466002)(498600001)(305945005)(356003)(6306002)(316002)(110136005)(966005)(54906003)(4326008)(53936002)(81156014)(81166006)(8676002)(53376002)(15188155005)(16799955002)(189998001)(44824005); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2698; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD015; 1:e8Vs6ctEbvTvQ4nUlXZI8xs9MoRNeN+r2/hdf2VNdAzmdAqF1UblG7grFGiDTJtfi0CsuFZmr1E230/28dwGIigz6CYdrl7oExNF5m20mDrrN8jlCyaMURwoTeNwCwv1 MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: efa459d6-2243-41e5-3d00-08d538d7765b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4628075)(201703131517081)(2017052603286); SRVR:DM5PR03MB2698; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2698; 3:0DmwrinVYrp+0yUpVgVFnlUc+C6RABJphyy6cQm5/Xn/eh90jM6QQAcadIHAs1MJ7ITgo7H3qOP4ipnisKHQQorOpxXI3AI56vj1uFzgf6a5FLh2wjmSruTW9HfLSNzjFqZ15qM61l/kVkYnF6EtunKrUQH2nUAfNg7arWfkApoMpyehMCnricBNBM0Swtxf+vOD/u+R1eod4Ni3MxFIrEsL+RHcDSyTTZoBuA7997quNnCYwPEv/XDr+nQzeoerNhwt6Ny5Yer73SetXEX0ZTHEsmWpHAHox7rCqhqeeMVVvR33A7OFSj4cmJRZ15lqIOHNT1tUsmxh1tcbhkT2PM+JzWAfnqmPe8ifYHA7WQE=; 25:XWYMqKUH9SDvrS18jeDmu9LlgeNQ9qx3wGqCuCkDoTtHlEOgdB/rPmKvvfbvYhrUwmW0Ikb5O4gQIh66VPpLK8JsN5OBGCsLcR7ASXQSemtwvxHlGExsi2b8x808zD3OAvxaH84ssMKO5EvUU6zpkp9Inh9qZUZOXD2TKUN5InPyk7xIndilSYNTPY7ymYCb071C42LoWTARvtl4J0qKphquOOvwRlficCVoRg/iax19YPrgpdB3CFaDn+SV4OccoIPyR6D5HPUkj3d1pm7ZRqg/BcqEfd7LjgZvjK/vOxeOgRkq4ElIWBrdmwUcTYLKErfMWJ3MU/nH1pQ5BqZjfw== X-MS-TrafficTypeDiagnostic: DM5PR03MB2698: X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2698; 31:pCGCbD3tjEhtce+KL9KZimG+LVLNf2UAWZo0yyPGjrsplubd43VHDuzLXSeXFXrYJ5PZ6mpH7WeJWik0MAVzKwH6cQhzZn27yCcC8MYAdp6i/HjZEttemZ9gtByxbehrN/XlWAAMJ/4WzebBdiH5xz25CwJ2R1/37LPI1DFZ2Mr9SOdO6eg0hbMIQF8n214zh6MFrViAG40zDoRqbvqlTrV7BI513z2pQoWyuEdXk7s=; 4:8wWi/lEplD9M5gOzO/T6L/q+kU8jTW1kJZwoDMfjs6IGuWuKtbiCD1x88BXr+6Q6hHloHw0n6JpfmEQn7F/zxw6KqPxbOuvHLxZ561H2ZCy+U8O7BpcfqJo42cw+mKu5h5FBW6gCJLpKLOVAchCCQ1e6CF9bBXsccRmlnMyGSArQFIAtIDTnxtzUE3bYmUbL7uB2HcQEyZd+KQ+twRV/aSIwxHgtRArpzBwREcZj+Myw/OGDTXBXyMPIHBVyzjFNTHf4c5c3Ae7V59sMFe1P2ncZBmjzO4bVtxZ4KqEmaaJN695y+VILGPIMwJSH4E8b X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(8121501046)(5005006)(3231022)(93006095)(93001095)(10201501046)(3002001)(6055026)(6096035)(20161123556025)(20161123559100)(20161123565025)(20161123561025)(20161123563025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(201708071742011); SRVR:DM5PR03MB2698; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:DM5PR03MB2698; X-Forefront-PRVS: 05087F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Ow06RQQvrugLP/FvH5BrQBS86j7gpjORj6WDb2A1PmnY7qCjraffuwDQA1uU5ys1vLknXUUJr9KeWJX1qoAklLB2ZinjROZM=; 24:vNwqW39ObN2xlDT9DCfTn2nkw0ZIqVkSIrf5AMCUUE5goKV5HRUBJKrPZHE9UCn1XwfXYm41o+ufaWC4hFQ9n0OtTESnqJhtT4FPDr2lDoQ=; 7:GdytI5HXkeY/5uQBl4V7qf4sw1ywl1v1nb4SGuJDBqsY9cRKsk2YQawm8B9VOduM+RZqGD5ci12WxBJevSpBCKExJsLTLTmF2neHheESNqsRW/KnuaxfykzIizDBJwsmlvCvMSqGYxDHucKUHpZYcMCbWsGK4plHXmQYV+oawx2jPijeFkd8zBfPdnbo8hPTWMyHMlPJ2J+QfPyv+aEZmcXvqcJK9cfekRJ34sWn6/gHGHEPzSQs/i41HCdBcORM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2017 16:20:39.5892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: efa459d6-2243-41e5-3d00-08d538d7765b X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2698 Subject: [edk2] [PATCH 2/3] Platform/NXP :Add Support of MMC Host Driver 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: , Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch adds support for MMC host driver Mmc host driver will produce gEfiMmcHostProtocolGuid which will be consumed by MmcDxe driver of EmbeddedPkg Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal Signed-off-by: Vabhav --- Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.c | 418 +++++++++++++++++++++= ++++ Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.inf | 42 +++ 2 files changed, 460 insertions(+) create mode 100644 Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.c create mode 100644 Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.inf diff --git a/Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.c b/Platform/NXP/Dr= ivers/MmcHostDxe/MmcHostDxe.c new file mode 100644 index 0000000..81269bf --- /dev/null +++ b/Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.c @@ -0,0 +1,418 @@ +/** @file + + This file implement the MMC Host Protocol for the NXP SDHC controller. + + Copyright 2017 NXP + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include +#include +#include +#include +#include +#include + +UINT8 LastCmd; +struct SdCmd Cmd; + +EFI_GUID mMmcDevicePathGuid =3D EFI_CALLER_ID_GUID; + +/** + Function to call library function to detect card presence + + @param This Pointer to MMC host protocol structure + +**/ +BOOLEAN +MmcIsCardPresent ( + IN EFI_MMC_HOST_PROTOCOL *This + ) +{ + return DetectCardPresence (); +} + +/** + Function to call library function to verify card is read only + + @param This Pointer to MMC host protocol structure + +**/ +BOOLEAN +MmcIsReadOnly ( + IN EFI_MMC_HOST_PROTOCOL *This + ) +{ + return IsCardReadOnly (); +} + +/** + Function to create command reseponse depeping upon + input command parameter + + @param MmcCmd MMC Command + +**/ +STATIC UINT32 +CreateResponseType ( + IN UINT32 MmcCmd + ) +{ + + UINT32 RespType; + + RespType =3D 0; + + if (MmcCmd & MMC_CMD_WAIT_RESPONSE) { + RespType =3D MMC_RSP_PRESENT; + + if (MmcCmd & MMC_CMD_LONG_RESPONSE) { + RespType |=3D (MMC_RSP_136|MMC_RSP_CRC); + } + else if (!(MmcCmd & MMC_CMD_NO_CRC_RESPONSE)) { + RespType |=3D (MMC_RSP_CRC|MMC_RSP_OPCODE); + } + } + + if (MMC_GET_INDX(MmcCmd) =3D=3D MMC_INDX(12)) { + RespType |=3D MMC_RSP_BUSY; + } + + return RespType; +} + +/** + Function to send MMC command + + @param This Pointer to MMC host protocol structure + @param MmcCmd MMC Command + @param Argument Argument if any + +**/ +EFI_STATUS +MmcSendCommand ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN MMC_CMD MmcCmd, + IN UINT32 Argument + ) +{ + EFI_STATUS Status; + + Cmd.CmdIdx =3D MMC_GET_INDX (MmcCmd); + Cmd.CmdArg =3D Argument; + Cmd.RespType =3D CreateResponseType (MmcCmd); + + //Saved data in Cmd struct for commands that need a read/write. + //This is done because which setting Xfertype register we need + //information of block number and blocksize. + if ((Cmd.CmdIdx =3D=3D MMC_INDX(6)) || (Cmd.CmdIdx =3D=3D MMC_INDX(51)) = || + (Cmd.CmdIdx =3D=3D MMC_INDX(17)) || (Cmd.CmdIdx =3D=3D MMC_INDX(18)= ) || + (Cmd.CmdIdx =3D=3D MMC_INDX(24)) || (Cmd.CmdIdx =3D=3D MMC_INDX(25)= )) { + + if ((Cmd.CmdIdx =3D=3D MMC_INDX(6)) && (LastCmd =3D=3D MMC_INDX(55))= ) { + Status =3D SendCmd (&Cmd, NULL); + } + else { + Status =3D EFI_SUCCESS; + } + } else { + Status =3D SendCmd (&Cmd, NULL); + } + + LastCmd =3D Cmd.CmdIdx; + + return Status; +} + +/** + Function to receive MMC command response + + @param This Pointer to MMC host protocol structure + @param Type MMC Command response type + @param Buffer Pointer to response Buffer + +**/ +EFI_STATUS +MmcReceiveResponse ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN MMC_RESPONSE_TYPE Type, + IN UINT32* Buffer + ) +{ + EFI_STATUS Status; + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (Type =3D=3D MMC_RESPONSE_TYPE_R2) { + Type |=3D MMC_RSP_136; + } else if (Type =3D=3D MMC_RESPONSE_TYPE_R1b) { + Type |=3D MMC_RSP_BUSY; + } + + DEBUG_MSG ("MMC_RESPONSE_TYPE 0x%x for cmd %d \n", Type, LastCmd); + + // if Last sent command is one among 6, 51, 17, 18, 24 and 25, then + // set data to 1 else 0 + if ((LastCmd =3D=3D MMC_INDX(6)) || (LastCmd =3D=3D MMC_INDX(51)) || + (LastCmd =3D=3D MMC_INDX(17)) || (LastCmd =3D=3D MMC_INDX(18)) || + (LastCmd =3D=3D MMC_INDX(24)) || (LastCmd =3D=3D MMC_INDX(25))) { + Status =3D RcvResp (Type, Buffer, 1); + } else { + Status =3D RcvResp (Type, Buffer, 0); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to receive response for %d \n", LastCmd)); + return Status; + } + + return Status; +} + +/** + Function to dump MMC data + + @param Buffer Pointer to MMC data + @param Length Length of MMC data + +**/ +VOID +DumpData ( + IN UINT32* Buffer, + IN UINTN Length + ) +{ +#ifdef MMC_DEBUG_READ + UINT32 Temp; + + DEBUG ((DEBUG_ERROR, "DATA IS (%d) :", Length)); + for (Temp =3D 1; Temp <=3D Length; Temp++) { + DEBUG ((DEBUG_ERROR, "0x%x ", Buffer[Temp-1])); + if ((Temp !=3D 0) && !(Temp % 8)) + DEBUG ((DEBUG_ERROR, "--- %d\n", Temp-1)); + } + DEBUG ((DEBUG_ERROR, "\n")); +#endif +} + +/** + Function to read MMC Data Block + + @param This Pointer to MMC host protocol structure + @param Lba + @param Length Length of MMC data + @param Buffer Pointer to MMC data + +**/ +EFI_STATUS +MmcReadBlockData ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Length, + IN UINT32* Buffer + ) +{ + EFI_STATUS RetVal; + EFI_TPL Tpl; + UINT8 Temp; + + // Raise the TPL at the highest level to disable Interrupts. + Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); + + //send Cmd structure here, library will send this command. + RetVal =3D ReadBlock (Lba, Length, Buffer, Cmd); + + if (Cmd.CmdIdx =3D=3D MMC_INDX(6)) { + for (Temp =3D 0; Temp < Length/8; Temp++) { + Buffer[Temp] =3D SwapBytes32(Buffer[Temp]); + } + } + + if (RetVal =3D=3D EFI_SUCCESS) { + DumpData(Buffer, Length); + } + + // Restore Tpl + gBS->RestoreTPL (Tpl); + + return RetVal; +} + +/** + Function to write MMC Data Block + + @param This Pointer to MMC host protocol structure + @param Lba + @param Length Length of MMC data block to be written + @param Buffer Pointer to MMC data + +**/ +EFI_STATUS +MmcWriteBlockData ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Length, + IN UINT32* Buffer + ) +{ + EFI_STATUS RetVal; + EFI_TPL Tpl; + + // Raise the TPL at the highest level to disable Interrupts. + Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); + + //send Cmd structure here, library will send this command. + RetVal =3D WriteBlock (Lba, Length, Buffer, Cmd); + + // Restore Tpl + gBS->RestoreTPL (Tpl); + + return RetVal; +} + +/** + Function to notify for different MMC states + + @param This Pointer to MMC host protocol structure + @param State MMC State + +**/ +EFI_STATUS +MmcNotifyState ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN MMC_STATE State + ) +{ + EFI_STATUS Status; + + switch (State) { + case MmcInvalidState: + ASSERT (0); + break; + case MmcHwInitializationState: + DEBUG ((DEBUG_ERROR, "MmcNotifyState(MmcHwInitializationState)\n")); + + Status =3D MmcInitialize(); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR,"Failed to init MMC\n")); + return Status; + } + break; + case MmcIdleState: + case MmcReadyState: + case MmcIdentificationState: + case MmcStandByState: + case MmcTransferState: + case MmcSendingDataState: + case MmcReceiveDataState: + case MmcProgrammingState: + case MmcDisconnectState: + break; + default: + ASSERT (0); + } + return EFI_SUCCESS; +} + +/** + Function to create device PATH for MMC node + + @param This Pointer to MMC host protocol structure + @param DevicePath Pointer to device path protocol structure + +**/ +EFI_STATUS +MmcBuildDevicePath ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN EFI_DEVICE_PATH_PROTOCOL **DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode; + + NewDevicePathNode =3D CreateDeviceNode (HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH)); + CopyGuid(&((VENDOR_DEVICE_PATH*)NewDevicePathNode)->Guid, &mMmcDevicePat= hGuid); + + *DevicePath =3D NewDevicePathNode; + return EFI_SUCCESS; +} + +/** + Function to set MMC speed + + @param This Pointer to MMC host protocol structure + @param BusClockFreq Bus clock frequency + @param BusWidth Bus width + @param TimingMode Timing mode + +**/ +EFI_STATUS +MmcSetIos ( + IN EFI_MMC_HOST_PROTOCOL *This, + IN UINT32 BusClockFreq, + IN UINT32 BusWidth, + IN UINT32 TimingMode + ) +{ + SetIos (BusClockFreq, BusWidth, TimingMode); + return EFI_SUCCESS; +} + +BOOLEAN +MmcIsMultBlk ( + IN EFI_MMC_HOST_PROTOCOL *This + ) +{ + return TRUE; +} + +EFI_MMC_HOST_PROTOCOL gMmcHost =3D { + MMC_HOST_PROTOCOL_REVISION, + MmcIsCardPresent, + MmcIsReadOnly, + MmcBuildDevicePath, + MmcNotifyState, + MmcSendCommand, + MmcReceiveResponse, + MmcReadBlockData, + MmcWriteBlockData, + MmcSetIos, + MmcIsMultBlk +}; + +/** + Function to install MMC Host Protocol gEfiMmcHostProtocolGuid +**/ +EFI_STATUS +MmcHostDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + Handle =3D NULL; + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiMmcHostProtocolGuid, &gMmcHost, + NULL + ); + + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "Failed to install gEfiMmcHostProtocolGuid\n")); + } + + return Status; +} diff --git a/Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.inf b/Platform/NXP/= Drivers/MmcHostDxe/MmcHostDxe.inf new file mode 100644 index 0000000..6761f3e --- /dev/null +++ b/Platform/NXP/Drivers/MmcHostDxe/MmcHostDxe.inf @@ -0,0 +1,42 @@ +#/**@file +# +# Copyright 2017 NXP +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +#**/ + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D MmcHostDxe + FILE_GUID =3D 7948a4ca-2f2e-41ca-90a2-d4420cecbbcf + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D MmcHostDxeEntryPoint + +[Sources.common] + MmcHostDxe.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + Platform/NXP/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MmcLib + TimerLib + UefiDriverEntryPoint + +[Protocols] + gEfiMmcHostProtocolGuid + +[Depex] + TRUE --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel