From patchwork Mon Oct 29 03:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Huang X-Patchwork-Id: 149620 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3598066ljp; Sun, 28 Oct 2018 20:33:16 -0700 (PDT) X-Google-Smtp-Source: AJdET5ceOBIUT1Gy2KkXcv+Z/GW1psY8xe15BmVFwdrOadDWyKubaDWz6vMhCRzrtMbqqn1BsMEf X-Received: by 2002:a63:e943:: with SMTP id q3-v6mr12186912pgj.42.1540783996632; Sun, 28 Oct 2018 20:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540783996; cv=none; d=google.com; s=arc-20160816; b=HmbkEm73W95a/nA7Lw04zIWUQX/zx7uyLnqz5c3pc0Svs8X7ogEspfzHd6L41dV1b3 BwnilnVeorongRvQDjH+a0Kv6sPZQppKUE02Ke25/Zg38/dy2fpykw2Vc/Tvplhbmvt+ b4xgGpLCbhzURE9JHdJjdVpG6OgocXcMkK0iRD60t35MW8+HpViPUuNCUec+mXVmFZhH jUuonRKfc58eWRTWS9RoXHFxsd5fWm7w3IQmVtsfI1AS56nYIY+jk8Rx/AdKtLBu1As1 8dTcmQrqBbT+wYj4qHJLIWjs1eYCXILnx2VRxlJYuBPI2SrdJxyxT5Ji6xa7hXEOpzE7 fshw== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=Fav8jC6Dop6uAnntrWJCo4cXCR5NbaVc3Tl/PlvTE6U=; b=ACLu5id5SUvWSksGew1dhfIa+rEI6MvGhwkvETmtk1w4t9U9CoUC2j4eeJO1EGQbVz h/b7SGy2x1Vc1fypXA7VLfVF2MznlB14LLsaQUz54cybNuipIntUyk2y+Mw8P3qyWJ3r pTjITQDQ6KIqggFDuT4oSnIu2gNDn6ho1QR+x//3t3C4uHxW6/a3PXxiAu7yC8QrGG/+ dMFfJhXqiHJdZWDQNY1W3jUpqYcSB2MBeafdEHFUg+wyoqZT3hPuHM6mx0NWoHGRI5yG mfzz4Wh0YBEOoeqM35jhuDw+R0x3MnzZ/Mqm826IKGpwnBMcV1vFoOqz0M62AUB8lbtd MUNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TZVBbMgi; 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 193-v6si20700145pgc.264.2018.10.28.20.33.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 20:33:16 -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.s=google header.b=TZVBbMgi; 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 45ABA21184AC8; Sun, 28 Oct 2018 20:33:16 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=ming.huang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 D9C362194D387 for ; Sun, 28 Oct 2018 20:33:14 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id bb7-v6so3094974plb.13 for ; Sun, 28 Oct 2018 20:33:14 -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:in-reply-to:references; bh=pI+iUcM+fJ+vW5CV9w1NihKulRq6BHb4MIBgXeU7Fj0=; b=TZVBbMgiNwB7tIwTGttVqCQTFvvx8rLW+PfCMk6T43JL/73hc+v1yk0czGeKs+3KeU QGnfrnq84TeKwmmcaVXEIcibQtqgs0y75NsDhmRCt5z7k1pDbKrJFSmzZbc441j+jf9S nFnM6FLq42GhPNc2SqFGlnjZvCYpRzZcrj5sU= 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=pI+iUcM+fJ+vW5CV9w1NihKulRq6BHb4MIBgXeU7Fj0=; b=hlZj0SYQstfe00BxAt0cFgdETnxeKJYVRHdQ/a+wEL5gULvqN1i6Ou2oZyw3mZ6onQ KScLySsL9yfLC8E0DI0HZpTiyb3HwX73B+zK9pOMqSUBwHJO5RdWHz4opzU91QrjoDz3 Grj7ZwtC0mPqKf0imAgIKX+0EaITqLPFzDLUiih2x2VfM3cZcLljWNpwVsvh5YmYOW+z /T5CtDKUFXeF+n1VWtH0ykTkpBVUdaXI8op0j2Db/wqvXW0AnMokyhmc50GZtJv2XcGn hfixWaBunBhsXrcqsKz8jwzHc7IMlLxYvNSZP65sCtJ1orAskuiEID4D2eXRnz6KgIAv U9sQ== X-Gm-Message-State: AGRZ1gKtY2+MLNn72aQS2Z6o3RbqWxOjroK0gjWD1gkPEDQSA3/kAlFp Aybt6yU8VuibO1cXg9Dn+yog3A== X-Received: by 2002:a17:902:e101:: with SMTP id cc1-v6mr12761696plb.165.1540783994358; Sun, 28 Oct 2018 20:33:14 -0700 (PDT) Received: from localhost.localdomain ([120.31.149.194]) by smtp.gmail.com with ESMTPSA id j5-v6sm22318872pgm.79.2018.10.28.20.33.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 20:33:13 -0700 (PDT) From: Ming Huang To: leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org Date: Mon, 29 Oct 2018 11:32:42 +0800 Message-Id: <20181029033249.45363-6-ming.huang@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181029033249.45363-1-ming.huang@linaro.org> References: <20181029033249.45363-1-ming.huang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v1 05/12] Hisilicon/D06: Move some functions to OemMiscLib 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: , Cc: huangming23@huawei.com, xinliang.liu@linaro.org, john.garry@huawei.com, zhangjinsong2@huawei.com, huangdaode@hisilicon.com, zhangfeng56@huawei.com, michael.d.kinney@intel.com, lersek@redhat.com, wanghuiqiang@huawei.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" As M41T83RealTimeClockLib is common library, so move two cpld relative functions to OemMiscLib and rename this two functions. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf | 1 - Silicon/Hisilicon/Include/Library/OemMiscLib.h | 9 ++ Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h | 4 - Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.c | 82 ++++++++++++++++++ Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c | 90 ++------------------ 5 files changed, 98 insertions(+), 88 deletions(-) -- 2.18.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf index e0bf6b3f24..4e963fd453 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf @@ -27,7 +27,6 @@ [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec - Platform/Hisilicon/D06/D06.dec Silicon/Hisilicon/HisiPkg.dec [LibraryClasses] diff --git a/Silicon/Hisilicon/Include/Library/OemMiscLib.h b/Silicon/Hisilicon/Include/Library/OemMiscLib.h index 86ea6a1b3d..0d7bf71b17 100644 --- a/Silicon/Hisilicon/Include/Library/OemMiscLib.h +++ b/Silicon/Hisilicon/Include/Library/OemMiscLib.h @@ -53,4 +53,13 @@ BOOLEAN OemIsNeedDisableExpanderBuffer(VOID); extern EFI_STRING_ID gDimmToDevLocator[MAX_SOCKET][MAX_CHANNEL][MAX_DIMM]; EFI_HII_HANDLE EFIAPI OemGetPackages (); + +VOID +OemReleaseOwnershipOfRtc ( + VOID + ); +EFI_STATUS +OemSwitchRtcI2cChannelAndLock ( + VOID + ); #endif diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h index d985055d9b..f329108858 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h @@ -16,12 +16,8 @@ #ifndef __M41T83_REAL_TIME_CLOCK_H__ #define __M41T83_REAL_TIME_CLOCK_H__ -// The delay is need for cpld and I2C. This is a empirical value. MemoryFence is no need. -#define RTC_DELAY_30_MS 30000 // The delay is need for cpld and I2C. This is a empirical value. MemoryFence is no need. #define RTC_DELAY_1000_MACROSECOND 1000 -// The delay is need for cpld and I2C. This is a empirical value. MemoryFence is no need. -#define RTC_DELAY_2_MACROSECOND 2 #define M41T83_REGADDR_DOTSECONDS 0x00 #define M41T83_REGADDR_SECONDS 0x01 diff --git a/Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.c b/Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.c index 2a9db46d1f..64d167d18a 100644 --- a/Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.c +++ b/Platform/Hisilicon/D06/Library/OemMiscLibD06/OemMiscLibD06.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,12 @@ #include #include #include +#include + +// The delay is need for cpld and I2C. This is a empirical value. MemoryFence is no need. +#define RTC_DELAY_30_MS 30000 +// The delay is need for cpld and I2C. This is a empirical value. MemoryFence is no need. +#define RTC_DELAY_2_MACROSECOND 2 REPORT_PCIEDIDVID2BMC PcieDeviceToReport[PCIEDEVICE_REPORT_MAX] = { {67,0,0,0}, @@ -207,3 +214,78 @@ OemIsNeedDisableExpanderBuffer ( { return TRUE; } + +EFI_STATUS +OemSwitchRtcI2cChannelAndLock ( + VOID + ) +{ + UINT8 Temp; + UINT8 Count; + + for (Count = 0; Count < 100; Count++) { + // To get the other side's state is idle first + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + if ((Temp & BIT3) != 0) { + (VOID) MicroSecondDelay (RTC_DELAY_30_MS); + // Try 100 times, if BMC has not released the bus, return preemption failed + if (Count == 99) { + if (!EfiAtRuntime ()) { + DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 times fail!\n", + __FUNCTION__, __LINE__)); + } + return EFI_DEVICE_ERROR; + } + continue; + } + + // if BMC free the bus, can be set 1 preemption + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp = Temp | CPU_GET_I2C_CONTROL; + // CPU occupied RTC I2C State + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); + (VOID) MicroSecondDelay (RTC_DELAY_2_MACROSECOND); + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + // Is preempt success + if(CPU_GET_I2C_CONTROL == (Temp & CPU_GET_I2C_CONTROL)) { + break; + } + if (Count == 99) { + if (!EfiAtRuntime ()) { + DEBUG((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state fail !!! \n", + __FUNCTION__, __LINE__)); + } + return EFI_DEVICE_ERROR; + } + (VOID) MicroSecondDelay (RTC_DELAY_30_MS); + } + + //Polling BMC RTC I2C status + for (Count = 0; Count < 100; Count++) { + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + if ((Temp & BIT3) == 0) { + return EFI_SUCCESS; + } + (VOID) MicroSecondDelay (RTC_DELAY_30_MS); + } + + //If the BMC occupies the RTC I2C Channel, write back the CPU side is idle + // or the subsequent BMC will not preempt + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp = Temp & (~CPU_GET_I2C_CONTROL); + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); + + return EFI_NOT_READY; +} + +VOID +OemReleaseOwnershipOfRtc ( + VOID + ) +{ + UINT8 Temp; + + Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); + Temp = Temp & ~CPU_GET_I2C_CONTROL; + WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); +} diff --git a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c index 0670f9c5f4..1f50ad4b64 100644 --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c @@ -17,10 +17,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -32,70 +32,6 @@ extern I2C_DEVICE gRtcDevice; STATIC EFI_LOCK mRtcLock; -EFI_STATUS -SwitchRtcI2cChannelAndLock ( - VOID - ) -{ - UINT8 Temp; - UINT8 Count; - - for (Count = 0; Count < 100; Count++) { - // To get the other side's state is idle first - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - if ((Temp & BIT3) != 0) { - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - // Try 100 times, if BMC has not released the bus, return preemption failed - if (Count == 99) { - if (!EfiAtRuntime ()) { - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state 100 times fail!\n", - __FUNCTION__, __LINE__)); - } - return EFI_DEVICE_ERROR; - } - continue; - } - - // if BMC free the bus, can be set 1 preemption - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp = Temp | CPU_GET_I2C_CONTROL; - // CPU occupied RTC I2C State - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); - (VOID) MicroSecondDelay (RTC_DELAY_2_MACROSECOND); - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - // Is preempt success - if(CPU_GET_I2C_CONTROL == (Temp & CPU_GET_I2C_CONTROL)) { - break; - } - if (Count == 99) { - if (!EfiAtRuntime ()) { - DEBUG((DEBUG_ERROR, "[%a]:[%dL] Clear cpu_i2c_rtc_state fail !!! \n", - __FUNCTION__, __LINE__)); - } - return EFI_DEVICE_ERROR; - } - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - } - - //Polling BMC RTC I2C status - for (Count = 0; Count < 100; Count++) { - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - if ((Temp & BIT3) == 0) { - return EFI_SUCCESS; - } - (VOID) MicroSecondDelay (RTC_DELAY_30_MS); - } - - //If the BMC occupies the RTC I2C Channel, write back the CPU side is idle - // or the subsequent BMC will not preempt - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp = Temp & (~CPU_GET_I2C_CONTROL); - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); - - return EFI_NOT_READY; -} - - /** Read RTC content through its registers. @@ -142,18 +78,6 @@ RtcWrite ( return Status; } -VOID -ReleaseOwnershipOfRtc ( - VOID - ) -{ - UINT8 Temp; - - Temp = ReadCpldReg (CPLD_I2C_SWITCH_FLAG); - Temp = Temp & ~CPU_GET_I2C_CONTROL; - WriteCpldReg (CPLD_I2C_SWITCH_FLAG, Temp); -} - EFI_STATUS InitializeM41T83 ( @@ -178,7 +102,7 @@ InitializeM41T83 ( return Status; } - Status = SwitchRtcI2cChannelAndLock (); + Status = OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Get i2c preemption failed: %r\n", Status)); if (!EfiAtRuntime ()) { @@ -231,7 +155,7 @@ InitializeM41T83 ( Exit: // Release RTC Lock. - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); if (!EfiAtRuntime ()) { EfiReleaseLock (&mRtcLock); } @@ -274,7 +198,7 @@ LibSetTime ( return EFI_INVALID_PARAMETER; } - Status = SwitchRtcI2cChannelAndLock (); + Status = OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { return Status; } @@ -332,7 +256,7 @@ LibSetTime ( } Exit: - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); // Release RTC Lock. if (!EfiAtRuntime ()) { if (EFI_ERROR (Status)) { @@ -377,7 +301,7 @@ LibGetTime ( return EFI_INVALID_PARAMETER; } - Status = SwitchRtcI2cChannelAndLock (); + Status = OemSwitchRtcI2cChannelAndLock (); if (EFI_ERROR (Status)) { return Status; } @@ -422,7 +346,7 @@ LibGetTime ( } Exit: - ReleaseOwnershipOfRtc (); + OemReleaseOwnershipOfRtc (); // Release RTC Lock. if (!EfiAtRuntime ()) { if (EFI_ERROR (Status)) {