From patchwork Fri Jul 7 09:21:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 107190 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3167400qge; Fri, 7 Jul 2017 02:21:49 -0700 (PDT) X-Received: by 10.84.176.3 with SMTP id u3mr1893131plb.134.1499419309798; Fri, 07 Jul 2017 02:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499419309; cv=none; d=google.com; s=arc-20160816; b=MgMRx4bDmXEbPupKwdY2DH0DJAiFyalPBwVCB9K5LZESBRSIj0xO6VsCIKGWVUleEQ 4+rSENzTjztpTSl8XDQhWIQRRecwXagCKwVTGDseq8b9R29kJVJ+GjD+uHGielq3W5fs d2d4PAByTy03YpsdLzfc/CsvdfYe7lScX6OxxadfGfZ5WncN8m0ZH5N9Z0lbyUpb1GoK zqwgJeq0O+Y+DkeYKLHL4wJTfOY8+5RD7rtqA70IpnEeizLVmwQhpykfyghtCbBFoqbG 8KbWogir5N1uEYseA7LXZoNPMFFuHsYgOr8x8o4acZwKe90shSeyXVDSXw7ZgoVpPBT/ hJmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=fH0pX8UcQ/iZlZEzjX+6lcrEyMtNZQeT1vhyGoz3p7I=; b=TkX9UeMIWBaBgzufi+mTvz0hL1SidZzN/0Lq62I3wLjt1v5/WlGmWhZBiWJEdrSCr7 izjlvy7n5JomLH3z4ctxqHkKaeuz2oSyKJCLhauxCI4nS0Mv55d9rWPP9hVul/x1Hk3Q qoci0hZc5edyDJfaouTKmzg7hGEJlrj8Hc5V1DHUBf75Her4N01f3irz3D8TySYrzB9k pUrRtjHbL5umE7pe+URwpJ9GjxZY/ivlUTpJ8cJoFYVAmc+TiHh0FFx8cYy0KErgObp5 EOkg0OoDu+ZdVgnr/ATT3ETW+ZKT5IYUw6Goe3GEH3beBxXuXZeR9JIz6l1ndH55H7tm Ve1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=FB3PSTUm; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id p61si2083147plb.100.2017.07.07.02.21.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jul 2017 02:21:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=FB3PSTUm; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 975D221CC5375; Fri, 7 Jul 2017 02:20:07 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-pf0-x22a.google.com (mail-pf0-x22a.google.com [IPv6:2607:f8b0:400e:c00::22a]) (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 8F0FF21BADACE for ; Fri, 7 Jul 2017 02:20:06 -0700 (PDT) Received: by mail-pf0-x22a.google.com with SMTP id q85so14465472pfq.1 for ; Fri, 07 Jul 2017 02:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JlnRPDgTZQJu6OfvOw2lxWBUzlnhwF+FDLl4OmLHeXg=; b=FB3PSTUmoIq0jGuBfYB/RTQ4fr7gT1cisGiopueRzrR2sfWNX6CTzrzX349VUG1HF6 EMIn3M6ERSsDGLJp0yZqvwJknZYYHD1xh/bpGaACeAGApyC/MxtJjvs+w8P+srO0DCbv KLsPpGMUM/5O/aZirn8r4RTyYZ7SQSqK2s5HI= 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; bh=JlnRPDgTZQJu6OfvOw2lxWBUzlnhwF+FDLl4OmLHeXg=; b=hqFBpYdSKKG/JdGL71hB440tEgRnYjc/H8xanjrHXP3ZzIAylIdXlNW8+z+i1zuWf/ Nu28k0SWZNx4mzdLTbZT9myjK1eXiZNEtb5R0pBG/uUoFHvADzyZ5ldoR8PPPT8wa/eu PKvbXn6tze4jqeMonM6nTNr40SXm6xbRPL8MOBUcN3l1rmrFGvRXcblHkEw2BT3ZkmVD XEJhes4kGdP5IF0kiVGLYII/RLpBjwXmB82UGF9Y5OCTipJlqsGE9PU3layELSj/VfI6 CglsTqKOlXHQGb4B5vtdAueYjSqpcPaEDwjEYFFjxNwbHxGutx2AfhUyE4J7hzoPEw7W /P9w== X-Gm-Message-State: AIVw112MGOVovSEJkrOQ+rhAI690czqZ46fQ51gwtt1L6LSWmlLDuGMg EhDDg7JMkTia/9cO X-Received: by 10.84.225.19 with SMTP id t19mr1855743plj.238.1499419307738; Fri, 07 Jul 2017 02:21:47 -0700 (PDT) Received: from localhost.localdomain ([113.53.228.78]) by smtp.gmail.com with ESMTPSA id s87sm5793192pfa.86.2017.07.07.02.21.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Jul 2017 02:21:47 -0700 (PDT) From: Jun Nie To: haojian.zhuang@linaro.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org, linaro-uefi@lists.linaro.org Date: Fri, 7 Jul 2017 17:21:37 +0800 Message-Id: <1499419297-18886-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v3 2/2] EmbeddedPkg/DwEmmc: Adjust FIFO threshold 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: , Cc: jason.liu@linaro.org, shawn.guo@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Adjust FIFO threshold according to FIFO depth. Skip the adjustment if we do not have FIFO depth info. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jun Nie --- EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h | 6 +++++ EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c | 42 +++++++++++++++++++++++++++++ EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf | 1 + EmbeddedPkg/EmbeddedPkg.dec | 1 + 4 files changed, 50 insertions(+) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Acked-by: Haojian Zhuang Reviewed-by: Leif Lindholm diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h index 055f1e0..90c7676 100644 --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h @@ -38,7 +38,10 @@ #define DWEMMC_RINTSTS ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x044) #define DWEMMC_STATUS ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x048) #define DWEMMC_FIFOTH ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x04c) +#define DWEMMC_TCBCNT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x05c) +#define DWEMMC_TBBCNT ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x060) #define DWEMMC_DEBNCE ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x064) +#define DWEMMC_HCON ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x070) #define DWEMMC_UHSREG ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x074) #define DWEMMC_BMOD ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x080) #define DWEMMC_DBADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x088) @@ -47,6 +50,7 @@ #define DWEMMC_DSCADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x094) #define DWEMMC_BUFADDR ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x098) #define DWEMMC_CARDTHRCTL ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X100) +#define DWEMMC_DATA ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X200) #define CMD_UPDATE_CLK 0x80202000 #define CMD_START_BIT (1 << 31) @@ -124,4 +128,6 @@ #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/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c index bb26b69..bd20f4b 100644 --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c @@ -415,6 +415,47 @@ DwEmmcReceiveResponse ( return EFI_SUCCESS; } +VOID +DwEmmcAdjustFifothresholdreshold ( + VOID + ) +{ + /* DMA multiple transaction size map to reg value as array index */ + CONST UINT32 BurstSize[] = {1, 4, 8, 16, 32, 64, 128, 256}; + UINT32 BlkDepthInFifo, Fifothreshold, FifoWidth, FifoDepth; + UINT32 BlkSize = DWEMMC_BLOCK_SIZE, Idx = 0, RxWatermark = 1, TxWatermark, TxWatermarkInvers; + + /* Skip FIFO adjustment if we do not have platform FIFO depth info */ + FifoDepth = PcdGet32 (PcdDwEmmcDxeFifoDepth); + if (!FifoDepth) { + return; + } + + TxWatermark = FifoDepth / 2; + TxWatermarkInvers = FifoDepth - TxWatermark; + + FifoWidth = DWEMMC_GET_HDATA_WIDTH (MmioRead32 (DWEMMC_HCON)); + if (!FifoWidth) { + FifoWidth = 2; + } else if (FifoWidth == 2) { + FifoWidth = 8; + } else { + FifoWidth = 4; + } + + BlkDepthInFifo = BlkSize / FifoWidth; + + Idx = ARRAY_SIZE (BurstSize) - 1; + while (Idx && ((BlkDepthInFifo % BurstSize[Idx]) || (TxWatermarkInvers % BurstSize[Idx]))) { + Idx--; + } + + RxWatermark = BurstSize[Idx] - 1; + Fifothreshold = DWEMMC_DMA_BURST_SIZE (Idx) | DWEMMC_FIFO_TWMARK (TxWatermark) + | DWEMMC_FIFO_RWMARK (RxWatermark); + MmioWrite32 (DWEMMC_FIFOTH, Fifothreshold); +} + EFI_STATUS PrepareDmaData ( IN DWEMMC_IDMAC_DESCRIPTOR* IdmacDesc, @@ -633,6 +674,7 @@ DwEmmcDxeInitialize ( Handle = NULL; + DwEmmcAdjustFifothresholdreshold (); gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DESC_PAGES); if (gpIdmacDesc == NULL) { return EFI_BUFFER_TOO_SMALL; diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf index 99b4f99..bc4413e 100644 --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf @@ -49,6 +49,7 @@ gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz + gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth [Depex] TRUE diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index 3cb30a4..4cd528a 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -168,6 +168,7 @@ gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0x0|UINT32|0x00000035 gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|0x0|UINT32|0x00000036 gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz|0x0|UINT32|0x00000037 + gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth|0x0|UINT32|0x00000038 # # Android FastBoot