From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4864:20::244; helo=mail-lj1-x244.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) (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 3059221A00AE6 for ; Fri, 9 Nov 2018 15:02:06 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id e5-v6so2963908lja.4 for ; Fri, 09 Nov 2018 15:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W8jWDbgGSErCBjieZmjD+DVitSfdbG6UNCLYtzwy2GE=; b=rSiITG/U14F4zW3Ex/cS0vO9fA2aYv21MEseDj5My9y1CMvCmt62GxWMmOct+nDGwL fIKoq82u1yz0O3VuRaGiBX33cnkSBIQJg47pzgwdn55Xg6cr6HGR+JIl50UoWU8bK7FN G6M4t/jpfRJPtQu6nFPeoicl+HqqM9XYBeq94jCU6zbqBH6OxuSamcyNkSmSTp0asniz nF+u9kbdVnON1QbkVPHcrwHMVOAIBSF9rTyfITOKkRiXyvoJFijeDF9AKj9Up9b9gmGj Xr0dwEwrfV4aCZvp/KaXkBTYQk4aKuxLGozybcL/Q+NHV8xKXmvmPkm49jXtgjrth5bL GVGA== 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:in-reply-to :references; bh=W8jWDbgGSErCBjieZmjD+DVitSfdbG6UNCLYtzwy2GE=; b=uPvjDN5tsvMguYZ2NnPF6oQvnZglGLFgCAPSbvmXQb4qhfm/pJ83O5Xgim7HkdxNq9 RUWD6RBLXfwGJRFqhG7luQwWdMkXv2wLvfws1+xj2NRg4WpF/5tvoXNoFNMdcsgIX+rp A7AETOw+u3XXTjVDNeF+SjyK4ZQx9WbzlLw/1CZY6QJBVEcFwFdYLKubUlU03qvUF3LA x8kjbKDSOOwVdW1w9Zj4Sj3kTRgdVNoqq2fBlotDYcubMlbsgo3c+gG0ELMQaRaxvvgk TIatIUWLfii+AMretU+/TUH9V6IeabhgS5MBQYRa+gDdc7kb6fSiR0hrHVDQcLD56wqP Bfbw== X-Gm-Message-State: AGRZ1gKj9eTQ1sh0NHfTue32oDA4WWD2pgOdoERf/gBkx1drpATv5UlQ iqXOjTUMzMa4tBf646PoHOWAGvpeF2w= X-Google-Smtp-Source: AJdET5euEt6gtkUVMqCjE+N7Kk8umvhcXDyriYdiGMeNLetXuAlqYp5LGnk8zvu9iVklO4GG5ro4Yw== X-Received: by 2002:a2e:9017:: with SMTP id h23-v6mr5839335ljg.71.1541804523616; Fri, 09 Nov 2018 15:02:03 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id c22sm1574318lfd.88.2018.11.09.15.02.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Nov 2018 15:02:02 -0800 (PST) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, hao.a.wu@intel.com, michael.d.kinney@intel.com, liming.gao@intel.com, ard.biesheuvel@linaro.org, nadavh@marvell.com, mw@semihalf.com, jsd@semihalf.com, tm@semihalf.com, jaz@semihalf.com Date: Sat, 10 Nov 2018 00:01:27 +0100 Message-Id: <1541804487-27458-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541804487-27458-1-git-send-email-mw@semihalf.com> References: <1541804487-27458-1-git-send-email-mw@semihalf.com> Subject: [PATCH v4 4/4] MdeModulePkg/SdMmcPciHcDxe: Allow overriding base clock frequency 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: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 X-List-Received-Date: Fri, 09 Nov 2018 23:02:06 -0000 Some SdMmc host controllers are run by clocks with different frequency than it is reflected in Capabilities Register 1. It is allowed by SDHCI specification ver. 4.2 - if BaseClkFreq field value of the Capability Register 1 is zero, the clock frequency must be obtained via another method. Because the bitfield is only 8 bits wide, a maximum value that could be obtained from hardware is 255MHz. In case the actual frequency exceeds 255MHz, the 8-bit BaseClkFreq member of SD_MMC_HC_SLOT_CAP structure occurs to be not sufficient to be used for setting the clock speed in SdMmcHcClockSupply function. This patch adds new UINT32 array ('BaseClkFreq[]') to SD_MMC_HC_PRIVATE_DATA structure for specifying the input clock speed for each slot of the host controller. All routines that are used for clock configuration are updated accordingly. This patch also adds new IN OUT BaseClockFreq field in the Capability callback of the SdMmcOverride, protocol which allows to update BaseClkFreq value. The patch reuses original commit from edk2-platforms: 20f6f144d3a8 ("Marvell/Drivers: XenonDxe: Allow overriding base clock frequency") Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas Reviewed-by: Ard Biesheuvel --- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 6 +++++ MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h | 8 +++---- MdeModulePkg/Include/Protocol/SdMmcOverride.h | 7 ++++-- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 4 ++-- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 4 ++-- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 13 ++++++++++- MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 23 ++++++++++---------- 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h index c683600..8c1a589 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h @@ -118,6 +118,12 @@ typedef struct { UINT64 MaxCurrent[SD_MMC_HC_MAX_SLOT]; UINT32 ControllerVersion; + + // + // Some controllers may require to override base clock frequency + // value stored in Capabilities Register 1. + // + UINT32 BaseClkFreq[SD_MMC_HC_MAX_SLOT]; } SD_MMC_HC_PRIVATE_DATA; #define SD_MMC_HC_TRB_SIG SIGNATURE_32 ('T', 'R', 'B', 'T') diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h index b47b0df..dd45cbd 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h @@ -423,7 +423,7 @@ SdMmcHcStopClock ( @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] ClockFreq The max clock frequency to be set. The unit is KHz. - @param[in] Capability The capability of the slot. + @param[in] BaseClkFreq The base clock frequency of host controller in MHz. @retval EFI_SUCCESS The clock is supplied successfully. @retval Others The clock isn't supplied successfully. @@ -434,7 +434,7 @@ SdMmcHcClockSupply ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT64 ClockFreq, - IN SD_MMC_HC_SLOT_CAP Capability + IN UINT32 BaseClkFreq ); /** @@ -482,7 +482,7 @@ SdMmcHcSetBusWidth ( @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. + @param[in] BaseClkFreq The base clock frequency of host controller in MHz. @retval EFI_SUCCESS The clock is supplied successfully. @retval Others The clock isn't supplied successfully. @@ -492,7 +492,7 @@ EFI_STATUS SdMmcHcInitClockFreq ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, - IN SD_MMC_HC_SLOT_CAP Capability + IN UINT32 BaseClkFreq ); /** diff --git a/MdeModulePkg/Include/Protocol/SdMmcOverride.h b/MdeModulePkg/Include/Protocol/SdMmcOverride.h index 6160b5b..0aaf258 100644 --- a/MdeModulePkg/Include/Protocol/SdMmcOverride.h +++ b/MdeModulePkg/Include/Protocol/SdMmcOverride.h @@ -22,7 +22,7 @@ #define EDKII_SD_MMC_OVERRIDE_PROTOCOL_GUID \ { 0xeaf9e3c1, 0xc9cd, 0x46db, { 0xa5, 0xe5, 0x5a, 0x12, 0x4c, 0x83, 0x23, 0x23 } } -#define EDKII_SD_MMC_OVERRIDE_PROTOCOL_VERSION 0x1 +#define EDKII_SD_MMC_OVERRIDE_PROTOCOL_VERSION 0x2 typedef struct _EDKII_SD_MMC_OVERRIDE EDKII_SD_MMC_OVERRIDE; @@ -58,6 +58,8 @@ typedef enum { @param[in] ControllerHandle The EFI_HANDLE of the controller. @param[in] Slot The 0 based slot index. @param[in,out] SdMmcHcSlotCapability The SDHCI capability structure. + @param[in,out] BaseClkFreq The base clock frequency value that + optionally can be updated. @retval EFI_SUCCESS The override function completed successfully. @retval EFI_NOT_FOUND The specified controller or slot does not exist. @@ -69,7 +71,8 @@ EFI_STATUS (EFIAPI * EDKII_SD_MMC_CAPABILITY) ( IN EFI_HANDLE ControllerHandle, IN UINT8 Slot, - IN OUT VOID *SdMmcHcSlotCapability + IN OUT VOID *SdMmcHcSlotCapability, + IN OUT UINT32 *BaseClkFreq ); /** diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c index b75a9bb..2d3fb68 100755 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c @@ -707,7 +707,7 @@ EmmcSwitchClockFreq ( // // Convert the clock freq unit from MHz to KHz. // - Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->Capability[Slot]); + Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->BaseClkFreq[Slot]); if (EFI_ERROR (Status)) { return Status; } @@ -1007,7 +1007,7 @@ EmmcSetBusMode ( return Status; } - ASSERT (Private->Capability[Slot].BaseClkFreq != 0); + ASSERT (Private->BaseClkFreq[Slot] != 0); // // Check if the Host Controller support 8bits bus width. // diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c index 32fd416..68485c8 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c @@ -864,7 +864,7 @@ SdCardSetBusMode ( return Status; } - Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, *Capability); + Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->BaseClkFreq[Slot]); if (EFI_ERROR (Status)) { return Status; } @@ -1064,7 +1064,7 @@ SdCardIdentification ( goto Error; } - SdMmcHcInitClockFreq (PciIo, Slot, Private->Capability[Slot]); + SdMmcHcInitClockFreq (PciIo, Slot, Private->BaseClkFreq[Slot]); gBS->Stall (1000); diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c index bf9869d..a87f8de 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c @@ -625,11 +625,16 @@ SdMmcPciHcDriverBindingStart ( if (EFI_ERROR (Status)) { continue; } + + Private->BaseClkFreq[Slot] = Private->Capability[Slot].BaseClkFreq; + if (mOverride != NULL && mOverride->Capability != NULL) { Status = mOverride->Capability ( Controller, Slot, - &Private->Capability[Slot]); + &Private->Capability[Slot], + &Private->BaseClkFreq[Slot] + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_WARN, "%a: Failed to override capability - %r\n", __FUNCTION__, Status)); @@ -637,6 +642,12 @@ SdMmcPciHcDriverBindingStart ( } } DumpCapabilityReg (Slot, &Private->Capability[Slot]); + DEBUG (( + DEBUG_INFO, + "Slot[%d] Base Clock Frequency: %dMHz\n", + Slot, + Private->BaseClkFreq[Slot] + )); Support64BitDma &= Private->Capability[Slot].SysBus64; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c index c3eec8b..ddf6dcf 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c @@ -721,7 +721,7 @@ SdMmcHcStopClock ( @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] ClockFreq The max clock frequency to be set. The unit is KHz. - @param[in] Capability The capability of the slot. + @param[in] BaseClkFreq The base clock frequency of host controller in MHz. @retval EFI_SUCCESS The clock is supplied successfully. @retval Others The clock isn't supplied successfully. @@ -732,11 +732,10 @@ SdMmcHcClockSupply ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, IN UINT64 ClockFreq, - IN SD_MMC_HC_SLOT_CAP Capability + IN UINT32 BaseClkFreq ) { EFI_STATUS Status; - UINT32 BaseClkFreq; UINT32 SettingFreq; UINT32 Divisor; UINT32 Remainder; @@ -746,9 +745,8 @@ SdMmcHcClockSupply ( // // Calculate a divisor for SD clock frequency // - ASSERT (Capability.BaseClkFreq != 0); + ASSERT (BaseClkFreq != 0); - BaseClkFreq = Capability.BaseClkFreq; if (ClockFreq == 0) { return EFI_INVALID_PARAMETER; } @@ -940,7 +938,7 @@ SdMmcHcSetBusWidth ( @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. + @param[in] BaseClkFreq The base clock frequency of host controller in MHz. @retval EFI_SUCCESS The clock is supplied successfully. @retval Others The clock isn't supplied successfully. @@ -950,16 +948,19 @@ EFI_STATUS SdMmcHcInitClockFreq ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Slot, - IN SD_MMC_HC_SLOT_CAP Capability + IN UINT32 BaseClkFreq ) { EFI_STATUS Status; UINT32 InitFreq; // - // Calculate a divisor for SD clock frequency + // According to SDHCI specification ver. 4.2, BaseClkFreq field value of + // the Capability Register 1 can be zero, which means a need for obtaining + // the clock frequency via another method. Fail in case it is not updated + // by SW at this point. // - if (Capability.BaseClkFreq == 0) { + if (BaseClkFreq == 0) { // // Don't support get Base Clock Frequency information via another method // @@ -969,7 +970,7 @@ SdMmcHcInitClockFreq ( // Supply 400KHz clock frequency at initialization phase. // InitFreq = 400; - Status = SdMmcHcClockSupply (PciIo, Slot, InitFreq, Capability); + Status = SdMmcHcClockSupply (PciIo, Slot, InitFreq, BaseClkFreq); return Status; } @@ -1103,7 +1104,7 @@ SdMmcHcInitHost ( PciIo = Private->PciIo; Capability = Private->Capability[Slot]; - Status = SdMmcHcInitClockFreq (PciIo, Slot, Capability); + Status = SdMmcHcInitClockFreq (PciIo, Slot, Private->BaseClkFreq[Slot]); if (EFI_ERROR (Status)) { return Status; } -- 2.7.4