From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::233; helo=mail-wm0-x233.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) (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 83D3921BADAB2 for ; Fri, 3 Aug 2018 06:24:05 -0700 (PDT) Received: by mail-wm0-x233.google.com with SMTP id w24-v6so6412793wmc.1 for ; Fri, 03 Aug 2018 06:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lO1VD/a+c0w+waqTqUGHqsOv5hh8MEhhctmvLL1ta14=; b=AbHn2hKi+rPVC4Qz+yNW+i8K4OG/mZFznGQF+puIwSXwzn6q6/fdkBD9xywZRQY61+ y0JT4I4zTcijLl1q8U6K9E2YH50lMrKbMh65yYcX+J69oNBgiDT7gG5nt+1THVBEgjk5 /8CLWZ9fefqgozx2d22JIjFIfjQgr+lyKqiBQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lO1VD/a+c0w+waqTqUGHqsOv5hh8MEhhctmvLL1ta14=; b=PE22End84TuUz/OduE7f1jaEZR3HtkA+AGaDwYZDQUmbxoTK3LP3ncOcmk9HWDlBJo u98qYRzK+mttXz63yNyoGCVwfscYmpnknrMwBwOQzsHtouJB2b7oooahYNWWi5Os+/gr 8p32fFnCe6VrpiP9e4ITaPlodq9XzU6uyy6d07OXjT2m1vfmx6Ca8oI0YdHhGJaSdC7Q 5uPEKnZGcqer0a1MTpSFBTwIm7aH3yBgCeH+QX2XYtjcqlJTww14h8EprZXWZTwFIbWq gCAC+S2mX7aSHDiGjqyqesiIUk8DXfuD78tzrXxjX33IN+kY6UlNtcDeKUP06dTRAQjX iQZA== X-Gm-Message-State: AOUpUlGNHpku1rFyReqy2nPuuvFaoOz+X1nzeg5T5eseWj0BiXE4ciJ1 UiijI/tUKZhW/Vsoy3tp8QSnEg== X-Google-Smtp-Source: AAOMgpeye/XAa1b2g5E1eIFp2ul/TEWnNeu+r+j+CryNBIO8h/DTlZxD7wF1kDuu2fxresMZ1TLW5A== X-Received: by 2002:a1c:c3c4:: with SMTP id t187-v6mr5190312wmf.123.1533302643931; Fri, 03 Aug 2018 06:24:03 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id m200-v6sm6197512wma.32.2018.08.03.06.24.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Aug 2018 06:24:02 -0700 (PDT) Date: Fri, 3 Aug 2018 14:24:00 +0100 From: Leif Lindholm To: Ming Huang 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 Message-ID: <20180803132400.3hbh6gvibdq3qrup@bivouac.eciton.net> References: <20180724070922.63362-1-ming.huang@linaro.org> <20180724070922.63362-16-ming.huang@linaro.org> MIME-Version: 1.0 In-Reply-To: <20180724070922.63362-16-ming.huang@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) 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: Fri, 03 Aug 2018 13:24:07 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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'. 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. > + > + 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. / Leif > (VOID)I2C_Disable(I2cInfo->Socket, I2cInfo->Port); > > return EFI_SUCCESS; > -- > 2.17.0 >