From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=ming.huang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 9D65F210DF5EE for ; Wed, 8 Aug 2018 07:41:22 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id i26-v6so1232880pfo.12 for ; Wed, 08 Aug 2018 07:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=4O1vxH/NNlGFutzDO0koPZrjkGlAVtvIe5HWtcKTY3s=; b=c7NuRFcWIozZ2ars+ivKRvdImvyhQRWZzz/W0PtB9g86iZ4USql869Yg4qiYPP982h QQcqKvFd4QGsT/iynS+NI7fgPN5t8MlVQy81xYjrx3eRqOznz4wCk2wp7U2Tgspi/dPw zAHjNarNSe3jSfTZq4eL1VMGr60c+yrqH/db8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=4O1vxH/NNlGFutzDO0koPZrjkGlAVtvIe5HWtcKTY3s=; b=a3cs1BzzQIDmVN29evEO+YUWaLWYJJR5kEpnTE9HofeT90oukz+g0urpCyp7R/YhNc C7CYyGBV0cjKpuhnGRJItAAgE9aUVWXbUt93TEzDfx9Y3b2x9uZwRcdbwLjhFhwVX0NS zvLi/40mqZXPIuvtQ+wu+xxLbcYa4Q2rtjlWX+jgpuflINl/RveBOof2EIS9/6D2cgCv Wm703LkVPzopRlJQtUJzJ+ExAJ3DNw8Tb1ggrQpMLz9mX+aNvSYlNQCV24tRm20FlHpA rlp0QJtnWL9an+Umx0QYY4ak13xrshA8R0LZPPV750wWJEoj6JTStefoxFZf0RFvaZUD 6l/w== X-Gm-Message-State: AOUpUlEypNzQHR4URHyQUFyYNa1zZd5Ppz3l2RXjtoShHsUsvaaL82XJ uAYnu2OCnKlMY4tZD8ss+DkrdA== X-Google-Smtp-Source: AA+uWPxrftow3X+GBxxdCoe8B0LZ/YdCbXUUdezWPdg/xgRxpXDfa73lssfuTbkiMsJpo8GJyKY8aQ== X-Received: by 2002:a63:f244:: with SMTP id d4-v6mr2836259pgk.2.1533739282076; Wed, 08 Aug 2018 07:41:22 -0700 (PDT) Received: from [10.199.0.182] ([64.64.108.224]) by smtp.gmail.com with ESMTPSA id 22-v6sm8729582pfl.126.2018.08.08.07.41.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 07:41:21 -0700 (PDT) To: Leif Lindholm Cc: linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org, ard.biesheuvel@linaro.org, guoheyi@huawei.com, wanghuiqiang@huawei.com, huangming23@huawei.com, zhangjinsong2@huawei.com, huangdaode@hisilicon.com, john.garry@huawei.com, xinliang.liu@linaro.org, Heyi Guo References: <20180724070922.63362-1-ming.huang@linaro.org> <20180724070922.63362-16-ming.huang@linaro.org> <20180803132400.3hbh6gvibdq3qrup@bivouac.eciton.net> From: Ming Message-ID: Date: Wed, 8 Aug 2018 22:41:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180803132400.3hbh6gvibdq3qrup@bivouac.eciton.net> Subject: Re: [PATCH edk2-platforms v1 15/38] Silicon/Hisilicon/I2C: Optimize I2C library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Aug 2018 14:41:22 -0000 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 8bit ÔÚ 8/3/2018 9:24 PM, Leif Lindholm дµÀ: > On Tue, Jul 24, 2018 at 03:08:59PM +0800, Ming Huang wrote: >> The hunt of waiting TX/TX finish is used by ten times, >> so move there hunts to a function CheckI2CTimeOut. > > I approve of this change, but the subject is inaccurate. > > Please change 'optimize' to 'refactor'. > OK, change it in v2. > Some style comments below. > >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Ming Huang >> Signed-off-by: Heyi Guo >> --- >> Silicon/Hisilicon/Library/I2CLib/I2CHw.h | 4 + >> Silicon/Hisilicon/Library/I2CLib/I2CLib.c | 176 +++++++------------- >> 2 files changed, 65 insertions(+), 115 deletions(-) >> >> diff --git a/Silicon/Hisilicon/Library/I2CLib/I2CHw.h b/Silicon/Hisilicon/Library/I2CLib/I2CHw.h >> index aa561e929c..fa954c7937 100644 >> --- a/Silicon/Hisilicon/Library/I2CLib/I2CHw.h >> +++ b/Silicon/Hisilicon/Library/I2CLib/I2CHw.h >> @@ -265,5 +265,9 @@ >> UINT32 Val32; >> } I2C0_ENABLE_STATUS_U; >> >> +typedef enum { >> + I2CTx, >> + I2CRx >> +} I2CTransfer; >> >> #endif >> diff --git a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c >> index ecd2f07c4d..16636987a6 100644 >> --- a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c >> +++ b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c >> @@ -234,6 +234,42 @@ I2C_GetRxStatus(UINT32 Socket,UINT8 Port) >> return ulFifo.bits.rxflr; >> } >> >> +EFI_STATUS >> +EFIAPI >> +CheckI2CTimeOut ( >> + UINT32 Socket, >> + UINT8 Port, >> + I2CTransfer Transfer >> +) >> +{ >> + UINT32 ulTimes = 0; >> + UINT32 ulFifo; > > Are these ul short for unsigned long? > That's called Hungarian notation and explicitly forbidden by the > coding style. Please drop, throughout the patch. > The implemention of this function is copy from original. ul will be drop in v2. >> + >> + if (Transfer == I2CTx) { >> + ulFifo = I2C_GetTxStatus (Socket,Port); > > Space after ','. > >> + while (ulFifo != 0) { >> + I2C_Delay(2); >> + if (++ulTimes > I2C_READ_TIMEOUT) { >> + (VOID)I2C_Disable (Socket, Port); >> + return EFI_TIMEOUT; >> + } >> + ulFifo = I2C_GetTxStatus (Socket,Port); > > Space after ','. > >> + } >> + } >> + else { >> + ulFifo = I2C_GetRxStatus (Socket,Port); > > Space after ','. > >> + while (ulFifo == 0) { >> + I2C_Delay(2); >> + if (++ulTimes > I2C_READ_TIMEOUT) { >> + (VOID)I2C_Disable (Socket, Port); >> + return EFI_TIMEOUT; >> + } >> + ulFifo = I2C_GetRxStatus (Socket,Port); >> + } >> + } >> + return EFI_SUCCESS; >> +} >> + >> EFI_STATUS >> EFIAPI >> WriteBeforeRead(I2C_DEVICE *I2cInfo, UINT32 ulLength, UINT8 *pBuf) >> @@ -247,17 +283,11 @@ WriteBeforeRead(I2C_DEVICE *I2cInfo, UINT32 ulLength, UINT8 *pBuf) >> >> I2C_SetTarget(I2cInfo->Socket,I2cInfo->Port,I2cInfo->SlaveDeviceAddress); >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> + ulFifo = 0; >> for(ulCnt = 0; ulCnt < ulLength; ulCnt++) >> { >> ulTimes = 0; >> @@ -275,17 +305,8 @@ WriteBeforeRead(I2C_DEVICE *I2cInfo, UINT32 ulLength, UINT8 *pBuf) >> ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> } >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - ulTimes = 0; >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> return EFI_SUCCESS; >> @@ -313,16 +334,8 @@ I2CWrite(I2C_DEVICE *I2cInfo, UINT16 InfoOffset, UINT32 ulLength, UINT8 *pBuf) >> >> I2C_SetTarget(I2cInfo->Socket,I2cInfo->Port,I2cInfo->SlaveDeviceAddress); >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> >> @@ -336,17 +349,8 @@ I2CWrite(I2C_DEVICE *I2cInfo, UINT16 InfoOffset, UINT32 ulLength, UINT8 *pBuf) >> I2C_REG_WRITE(Base + I2C_DATA_CMD_OFFSET, InfoOffset & 0xff); >> } >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - ulTimes = 0; >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> for(Idx = 0; Idx < ulLength; Idx++) >> @@ -372,20 +376,10 @@ I2CWrite(I2C_DEVICE *I2cInfo, UINT16 InfoOffset, UINT32 ulLength, UINT8 *pBuf) >> } >> } >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - ulTimes = 0; >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - DEBUG ((EFI_D_ERROR, "I2C Write try to finished,time out!\n")); >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> + > > This added blank line is unrelated to the change. Please drop. > >> (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> >> return EFI_SUCCESS; >> @@ -395,8 +389,6 @@ EFI_STATUS >> EFIAPI >> I2CRead(I2C_DEVICE *I2cInfo, UINT16 InfoOffset,UINT32 ulRxLen,UINT8 *pBuf) >> { >> - UINT32 ulFifo; >> - UINT32 ulTimes = 0; >> UINT8 I2CWAddr[2]; >> EFI_STATUS Status; >> UINT32 Idx = 0; >> @@ -434,17 +426,8 @@ I2CRead(I2C_DEVICE *I2cInfo, UINT16 InfoOffset,UINT32 ulRxLen,UINT8 *pBuf) >> >> I2C_SetTarget(I2cInfo->Socket,I2cInfo->Port,I2cInfo->SlaveDeviceAddress); >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - >> - while(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> while (ulRxLen > 0) { >> @@ -455,16 +438,9 @@ I2CRead(I2C_DEVICE *I2cInfo, UINT16 InfoOffset,UINT32 ulRxLen,UINT8 *pBuf) >> I2C_REG_WRITE(Base + I2C_DATA_CMD_OFFSET, I2C_READ_SIGNAL | I2C_CMD_STOP_BIT); >> } >> >> - ulTimes = 0; >> - do { >> - I2C_Delay(2); >> - >> - while(++ulTimes > I2C_READ_TIMEOUT) { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetRxStatus(I2cInfo->Socket,I2cInfo->Port); >> - }while(0 == ulFifo); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CRx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> + } >> >> I2C_REG_READ(Base + I2C_DATA_CMD_OFFSET, pBuf[Idx++]); >> >> @@ -481,8 +457,6 @@ I2CReadMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset,UINT32 ulRxLen,UINT8 *pB >> { >> UINT32 ulCnt; >> UINT16 usTotalLen = 0; >> - UINT32 ulFifo; >> - UINT32 ulTimes = 0; >> UINT8 I2CWAddr[4]; >> EFI_STATUS Status; >> UINT32 BytesLeft; >> @@ -558,16 +532,9 @@ I2CReadMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset,UINT32 ulRxLen,UINT8 *pB >> >> >> for(ulCnt = 0; ulCnt < BytesLeft; ulCnt++) { >> - ulTimes = 0; >> - do { >> - I2C_Delay(2); >> - >> - while(++ulTimes > I2C_READ_TIMEOUT) { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetRxStatus(I2cInfo->Socket,I2cInfo->Port); >> - }while(0 == ulFifo); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CRx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> + } >> >> I2C_REG_READ(Base + I2C_DATA_CMD_OFFSET, pBuf[Idx++]); >> } >> @@ -580,8 +547,6 @@ EFI_STATUS >> EFIAPI >> I2CWriteMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset, UINT32 ulLength, UINT8 *pBuf) >> { >> - UINT32 ulFifo; >> - UINT32 ulTimes = 0; >> UINT32 Idx; >> UINTN Base; >> >> @@ -597,16 +562,8 @@ I2CWriteMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset, UINT32 ulLength, UINT8 >> >> I2C_SetTarget(I2cInfo->Socket,I2cInfo->Port,I2cInfo->SlaveDeviceAddress); >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> >> >> @@ -630,7 +587,6 @@ I2CWriteMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset, UINT32 ulLength, UINT8 >> >> } >> >> - ulTimes = 0; >> for(Idx = 0; Idx < ulLength; Idx++) >> { >> >> @@ -638,20 +594,10 @@ I2CWriteMultiByte(I2C_DEVICE *I2cInfo, UINT32 InfoOffset, UINT32 ulLength, UINT8 >> >> } >> >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> - ulTimes = 0; >> - while(0 != ulFifo) >> - { >> - I2C_Delay(2); >> - >> - if(++ulTimes > I2C_READ_TIMEOUT) >> - { >> - DEBUG ((EFI_D_ERROR, "I2C Write try to finished,time out!\n")); >> - (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> - return EFI_TIMEOUT; >> - } >> - ulFifo = I2C_GetTxStatus(I2cInfo->Socket,I2cInfo->Port); >> + if (CheckI2CTimeOut (I2cInfo->Socket,I2cInfo->Port,I2CTx) == EFI_TIMEOUT) { > > Space after ','. > >> + return EFI_TIMEOUT; >> } >> + > > Unrelated added blank line. Please drop. OK, all comments will apply in v2. Thanks. > > / > Leif > >> (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); >> >> return EFI_SUCCESS; >> -- >> 2.17.0 >>