From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web11.4263.1588592424685675821 for ; Mon, 04 May 2020 04:40:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PnGiZFiw; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588592423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MeJSeFMbwD+FFtZoEY39SDu+nJYwtJ4zopMFknihTKY=; b=PnGiZFiw49cNVxkjXVFKlM2/1VC6po6E5yZ4T4SRZKoapty7vd4RP3JBj8iMt8FOnqaKvs wnvKYUo20u/TYcO0ByOKm/k+HZsgNd8+Ez/mKrqK7KBaX1GTKtsNgChzQTHA31GnFTlFi8 mbiskN3PznOaLUwzVmJITeWceHNwbz8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-116-2M8xdOteOhqGF0X176bmlA-1; Mon, 04 May 2020 07:40:22 -0400 X-MC-Unique: 2M8xdOteOhqGF0X176bmlA-1 Received: by mail-wm1-f72.google.com with SMTP id f81so3345434wmf.2 for ; Mon, 04 May 2020 04:40:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=YKVzqm1YzHCnFYePgXphDYAwINJ6WBsIQicf7A/J8vY=; b=bdC5HKPMJHr/5jkIRvMpBjNogwByY3tyX/EzR/RkqQTmBADeLsiEgd2qGMidqVj0Jx f9BAdyRt4S0k9VoGO8NrtRXllivNfYXbIQNXecX8jErG10/M2dvB7iJmY9v5bPvu/x8E knPzSPo0Aqumm0vPPv+b2p1AHgZkavRJ72+wYiUNkSx0IBNU2V+TZKKhvHPThi1qK0Tq E25oHb55AqmC+d/JARXz1DLaXJE2A+SoDWm1AeK1asooJmr8g/c65npS76VH4kHwcQzL DHYc/Ukj34vHh8tujctBGo8nUAqXk25G3o+y8m5X7Me3JXcJvtsHDVpSydia/SntC3ds VaZQ== X-Gm-Message-State: AGi0PuYe5bB8LegWPG4RXEszzNkEC4KDlCvEUvqCchfF7BFX6FFmkHZ2 58jFqNKrGsWqqJm6w48IZyVPi4woI8Tief9NnBCqhfTskgJZZVzfs+YUiS7kuFJYa9x/VoiWx9K 7EbohOhalTvGBBA== X-Received: by 2002:a1c:e903:: with SMTP id q3mr13710991wmc.76.1588592420361; Mon, 04 May 2020 04:40:20 -0700 (PDT) X-Google-Smtp-Source: APiQypIKIWj9qe64f6aeDTu+cQjYO88yflnanUvr6kqYTdPc4GMQN9ZUY+dlSdCl8ElOzjHy4r9YQQ== X-Received: by 2002:a1c:e903:: with SMTP id q3mr13710960wmc.76.1588592420028; Mon, 04 May 2020 04:40:20 -0700 (PDT) Return-Path: Received: from [192.168.1.39] (26.red-88-21-207.staticip.rima-tde.net. [88.21.207.26]) by smtp.gmail.com with ESMTPSA id y9sm12452601wmm.26.2020.05.04.04.40.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2020 04:40:19 -0700 (PDT) Subject: Re: [edk2-devel] [PATCH edk2-platforms v3 4/8] Silicon/Synopsys/DesignWare: import eMMC DXE driver from EmbeddedPkg To: devel@edk2.groups.io, leif@nuviainc.com, Ard Biesheuvel References: <20200430171650.24139-1-ard.biesheuvel@arm.com> <20200430171650.24139-5-ard.biesheuvel@arm.com> <20200504105818.GD21486@vanye> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: Date: Mon, 4 May 2020 13:40:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200504105818.GD21486@vanye> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable On 5/4/20 12:58 PM, Leif Lindholm wrote: > On Thu, Apr 30, 2020 at 19:16:45 +0200, Ard Biesheuvel wrote: >> Incorporate the driver for the DesignWare eMMC host controller that is >> based on the obsolete MMC host controller protocol that is defined in >> EmbeddedPkg. >> >> This driver does not follow the UEFI driver model, and is only kept >> around for its only users, which is the HiKey platform, which is >> rapidly reaching obsolescence itself, at which point this driver may >> be removed again. >> >> To prevent inadvertent use in new platforms, add a PCD that needs to >> be changed from its default value in order for the driver to be >> functional. >> >> Signed-off-by: Ard Biesheuvel >> --- >> Silicon/Synopsys/DesignWare/DesignWare.dec | 9 + >> Silicon/Synopsys/DesignWare/DesignWare.dsc | 2 + >> Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmc.h | 132 ++++ >> Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c | 693 ++++= ++++++++++++++++ >> Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.inf | 56 ++ >> 5 files changed, 892 insertions(+) >> >> diff --git a/Silicon/Synopsys/DesignWare/DesignWare.dec b/Silicon/Synops= ys/DesignWare/DesignWare.dec >> index 71ddd24b7404..f7ec7927543c 100755 >> --- a/Silicon/Synopsys/DesignWare/DesignWare.dec >> +++ b/Silicon/Synopsys/DesignWare/DesignWare.dec >> @@ -21,4 +21,13 @@ [Guids.common] >> gDesignWareTokenSpaceGuid =3D { 0x89cb1241, 0xd283, 0x4543, { 0x88, = 0x9c, 0x6b, 0x62, 0x36, 0x1a, 0x95, 0x7a } } >> gDwEmacNetNonDiscoverableDeviceGuid =3D { 0x401950CD, 0xF9CD, 0x4A65= , { 0xAD, 0x8E, 0x84, 0x9F, 0x3B, 0xAF, 0x23, 0x04 } } >> =20 >> +[PcdsFixedAtBuild.common] >> + # >> + # Permit the use of obsolete drivers in this package >> + # >> + gDesignWareTokenSpaceGuid.PcdDwPermitObsoleteDrivers|FALSE|BOOLEAN|0x= 00000001 >> =20 >> + gDesignWareTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0x0|UINT32|0x000000= 02 >> + gDesignWareTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|0x0|UINT32|0= x00000003 >> + gDesignWareTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz|0x0|UINT32|0x0= 0000004 >> + gDesignWareTokenSpaceGuid.PcdDwEmmcDxeFifoDepth|0x0|UINT32|0x00000005 >> diff --git a/Silicon/Synopsys/DesignWare/DesignWare.dsc b/Silicon/Synops= ys/DesignWare/DesignWare.dsc >> index ad6a5ede4ae0..098bba3f7d68 100755 >> --- a/Silicon/Synopsys/DesignWare/DesignWare.dsc >> +++ b/Silicon/Synopsys/DesignWare/DesignWare.dsc >> @@ -20,6 +20,7 @@ [LibraryClasses] >> ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf >> BaseLib|MdePkg/Library/BaseLib/BaseLib.inf >> BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf >> + CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheM= aintenanceLib.inf >> DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf >> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf >> DmaLib|EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf >> @@ -39,3 +40,4 @@ [LibraryClasses] >> =20 >> [Components] >> Silicon/Synopsys/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.inf >> + Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.inf >> diff --git a/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmc.h b/Si= licon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmc.h >> new file mode 100644 >> index 000000000000..09ad9b8428c4 >> --- /dev/null >> +++ b/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmc.h >> @@ -0,0 +1,132 @@ >> +/** @file >> +* >> +* WARNING: >> +* This driver fails to follow the UEFI driver model without a good >> +* reason, and only remains in the tree because it is still used by >> +* a small number of platforms. It will be removed when no longer used. >> +* >> +* Copyright (c) 2014-2017, Linaro Limited. All rights reserved. >> +* >> +* SPDX-License-Identifier: BSD-2-Clause-Patent >> +* >> +**/ >> + >> + >> +#ifndef __DWEMMC_H__ >> +#define __DWEMMC_H__ >> + >> +#include >> + >> +// DW MMC Registers >> +#define DWEMMC_CTRL ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x000) >> +#define DWEMMC_PWREN ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x004) >> +#define DWEMMC_CLKDIV ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x008) >> +#define DWEMMC_CLKSRC ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x00c) >> +#define DWEMMC_CLKENA ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x010) >> +#define DWEMMC_TMOUT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x014) >> +#define DWEMMC_CTYPE ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x018) >> +#define DWEMMC_BLKSIZ ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x01c) >> +#define DWEMMC_BYTCNT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x020) >> +#define DWEMMC_INTMASK ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x024) >> +#define DWEMMC_CMDARG ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x028) >> +#define DWEMMC_CMD ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x02c) >> +#define DWEMMC_RESP0 ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x030) >> +#define DWEMMC_RESP1 ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x034) >> +#define DWEMMC_RESP2 ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x038) >> +#define DWEMMC_RESP3 ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x03c) >> +#define DWEMMC_RINTSTS ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x044) >> +#define DWEMMC_STATUS ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x048) >> +#define DWEMMC_FIFOTH ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x04c) >> +#define DWEMMC_TCBCNT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x05c) >> +#define DWEMMC_TBBCNT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x060) >> +#define DWEMMC_DEBNCE ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x064) >> +#define DWEMMC_HCON ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x070) >> +#define DWEMMC_UHSREG ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x074) >> +#define DWEMMC_BMOD ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x080) >> +#define DWEMMC_DBADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x088) >> +#define DWEMMC_IDSTS ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x08c) >> +#define DWEMMC_IDINTEN ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x090) >> +#define DWEMMC_DSCADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x094) >> +#define DWEMMC_BUFADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0x098) >> +#define DWEMMC_CARDTHRCTL ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0X100) >> +#define DWEMMC_DATA ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddr= ess) + 0X200) >> + >> +#define CMD_UPDATE_CLK 0x80202000 >> +#define CMD_START_BIT (1 << 31) >> + >> +#define MMC_8BIT_MODE (1 << 16) >> + >> +#define BIT_CMD_RESPONSE_EXPECT (1 << 6) >> +#define BIT_CMD_LONG_RESPONSE (1 << 7) >> +#define BIT_CMD_CHECK_RESPONSE_CRC (1 << 8) >> +#define BIT_CMD_DATA_EXPECTED (1 << 9) >> +#define BIT_CMD_READ (0 << 10) >> +#define BIT_CMD_WRITE (1 << 10) >> +#define BIT_CMD_BLOCK_TRANSFER (0 << 11) >> +#define BIT_CMD_STREAM_TRANSFER (1 << 11) >> +#define BIT_CMD_SEND_AUTO_STOP (1 << 12) >> +#define BIT_CMD_WAIT_PRVDATA_COMPLETE (1 << 13) >> +#define BIT_CMD_STOP_ABORT_CMD (1 << 14) >> +#define BIT_CMD_SEND_INIT (1 << 15) >> +#define BIT_CMD_UPDATE_CLOCK_ONLY (1 << 21) >> +#define BIT_CMD_READ_CEATA_DEVICE (1 << 22) >> +#define BIT_CMD_CCS_EXPECTED (1 << 23) >> +#define BIT_CMD_ENABLE_BOOT (1 << 24) >> +#define BIT_CMD_EXPECT_BOOT_ACK (1 << 25) >> +#define BIT_CMD_DISABLE_BOOT (1 << 26) >> +#define BIT_CMD_MANDATORY_BOOT (0 << 27) >> +#define BIT_CMD_ALTERNATE_BOOT (1 << 27) >> +#define BIT_CMD_VOLT_SWITCH (1 << 28) >> +#define BIT_CMD_USE_HOLD_REG (1 << 29) >> +#define BIT_CMD_START (1 << 31) >> + >> +#define DWEMMC_INT_EBE (1 << 15) /* End-= bit Err */ >> +#define DWEMMC_INT_SBE (1 << 13) /* Star= t-bit Err */ >> +#define DWEMMC_INT_HLE (1 << 12) /* Hard= ware-lock Err */ >> +#define DWEMMC_INT_FRUN (1 << 11) /* FIFO= UN/OV RUN */ >> +#define DWEMMC_INT_DRT (1 << 9) /* Data= timeout */ >> +#define DWEMMC_INT_RTO (1 << 8) /* Resp= onse timeout */ >> +#define DWEMMC_INT_DCRC (1 << 7) /* Data= CRC err */ >> +#define DWEMMC_INT_RCRC (1 << 6) /* Resp= onse CRC err */ >> +#define DWEMMC_INT_RXDR (1 << 5) >> +#define DWEMMC_INT_TXDR (1 << 4) >> +#define DWEMMC_INT_DTO (1 << 3) /* Data= trans over */ >> +#define DWEMMC_INT_CMD_DONE (1 << 2) >> +#define DWEMMC_INT_RE (1 << 1) >> + >> +#define DWEMMC_IDMAC_DES0_DIC (1 << 1) >> +#define DWEMMC_IDMAC_DES0_LD (1 << 2) >> +#define DWEMMC_IDMAC_DES0_FS (1 << 3) >> +#define DWEMMC_IDMAC_DES0_CH (1 << 4) >> +#define DWEMMC_IDMAC_DES0_ER (1 << 5) >> +#define DWEMMC_IDMAC_DES0_CES (1 << 30) >> +#define DWEMMC_IDMAC_DES0_OWN (1 << 31) >> +#define DWEMMC_IDMAC_DES1_BS1(x) ((x) & 0x1fff) >> +#define DWEMMC_IDMAC_DES2_BS2(x) (((x) & 0x1fff) << 13) >> +#define DWEMMC_IDMAC_SWRESET (1 << 0) >> +#define DWEMMC_IDMAC_FB (1 << 1) >> +#define DWEMMC_IDMAC_ENABLE (1 << 7) >> + >> +#define EMMC_FIX_RCA 6 >> + >> +/* bits in MMC0_CTRL */ >> +#define DWEMMC_CTRL_RESET (1 << 0) >> +#define DWEMMC_CTRL_FIFO_RESET (1 << 1) >> +#define DWEMMC_CTRL_DMA_RESET (1 << 2) >> +#define DWEMMC_CTRL_INT_EN (1 << 4) >> +#define DWEMMC_CTRL_DMA_EN (1 << 5) >> +#define DWEMMC_CTRL_IDMAC_EN (1 << 25) >> +#define DWEMMC_CTRL_RESET_ALL (DWEMMC_CTRL_RESET | DW= EMMC_CTRL_FIFO_RESET | DWEMMC_CTRL_DMA_RESET) >> + >> +#define DWEMMC_STS_DATA_BUSY (1 << 9) >> + >> +#define DWEMMC_FIFO_TWMARK(x) (x & 0xfff) >> +#define DWEMMC_FIFO_RWMARK(x) ((x & 0x1ff) << 16) >> +#define DWEMMC_DMA_BURST_SIZE(x) ((x & 0x7) << 28) >> + >> +#define DWEMMC_CARD_RD_THR(x) ((x & 0xfff) << 16) >> +#define DWEMMC_CARD_RD_THR_EN (1 << 0) >> + >> +#define DWEMMC_GET_HDATA_WIDTH(x) (((x) >> 7) & 0x7) >> + >> +#endif // __DWEMMC_H__ >> diff --git a/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c b= /Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c >> new file mode 100644 >> index 000000000000..eed5fc57fc22 >> --- /dev/null >> +++ b/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c >> @@ -0,0 +1,693 @@ >> +/** @file >> + This file implement the MMC Host Protocol for the DesignWare eMMC. >> + >> + Copyright (c) 2014-2017, Linaro Limited. All rights reserved. >> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > Comment only: > This file, unlike some other .c files in this series, does not include > the WARNING header. Feel free to fold one in before pushing. Good catch. Reviewed-by: Philippe Mathieu-Daud=E9 >=20 > / > Leif >=20 [...]