Re: [edk2] [PATCH edk2-platforms v2 06/15] Hisilicon/D06: Move some functions to OemMiscLib

2018-11-20 Thread Leif Lindholm
On Tue, Nov 20, 2018 at 02:38:32PM +0800, Ming Huang wrote:
> > My feedback was:
> > ---
> > This would be more clear as "platform specific" than "cpld relative".
> > 
> > I did not realise this wasn't a Hisilicon component when reviewing the
> > original set.
> > 
> > I approve of this change, but can you tell me why it is included in
> > this set? If the goal is to make the M41T83 support platform
> > independent, should the library also move to Silicon/ST/?
> > ---
> > 
> > So could you please update the commit message, and add a subsequent
> > patch moving Library/M41T83RealTimeClockLib to
> > Silicon/STMicroelectronics (and updating D06.dsc to match)?
> > I do not care if it is not perfectly abstracted yet - we can deal with
> > that when we have other users of the component in the tree.
> 
> Sorry for missing update the commit message this patch.
> I will update it in v3. I try to move the library to 
> Silicon/STMicroelectronics,
> but M41T83RealTimeClockLib depend on I2CLib in Hisilicon, so can't move the
> library to STMicroelectronics. Main gist of this patch
> is making this library as a common module in Hisilicon.

And a PCI component depends on PciLib - that does not mean it should
live in edk2 MdePkg. And it does not mean that this library should be
considered Hisilicon-specific. If we get other platforms with this
component, they will not be permitted to add duplicated code - we
will then need to make sure the library is suitable for all users.

There is no situation other than the maintainers (me) dropping the
ball that lets you have a private driver for a generic component.

Regardless, I will leave this patch out for now, to avoid delaying the
release.

/
Leif
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH edk2-platforms v2 06/15] Hisilicon/D06: Move some functions to OemMiscLib

2018-11-19 Thread Ming Huang



On 11/20/2018 2:30 AM, Leif Lindholm wrote:
> On Fri, Nov 16, 2018 at 02:56:53PM +0800, Ming Huang wrote:
>> 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 
> 
> I did not see any of my review comments addressed, or any response
> saying it was not being changed.
> 
> My feedback was:
> ---
> This would be more clear as "platform specific" than "cpld relative".
> 
> I did not realise this wasn't a Hisilicon component when reviewing the
> original set.
> 
> I approve of this change, but can you tell me why it is included in
> this set? If the goal is to make the M41T83 support platform
> independent, should the library also move to Silicon/ST/?
> ---
> 
> So could you please update the commit message, and add a subsequent
> patch moving Library/M41T83RealTimeClockLib to
> Silicon/STMicroelectronics (and updating D06.dsc to match)?
> I do not care if it is not perfectly abstracted yet - we can deal with
> that when we have other users of the component in the tree.

Sorry for missing update the commit message this patch.
I will update it in v3. I try to move the library to Silicon/STMicroelectronics,
but M41T83RealTimeClockLib depend on I2CLib in Hisilicon, so can't move the
library to STMicroelectronics. Main gist of this patch
is making this library as a common module in Hisilicon.

> 
> /
> Leif
> 
>> ---
>>  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(-)
>>
>> diff --git 
>> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>>  
>> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>> index e0bf6b3f24db..4e963fd4531a 100644
>> --- 
>> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>> +++ 
>> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>> @@ -27,7 +27,6 @@ [Sources.common]
>>  [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 86ea6a1b3deb..0d7bf71b17d2 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 d985055d9bb6..f32910885856 100644
>> --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
>> +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
>> @@ -17,11 +17,7 @@
>>  #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_MS3
>> -// 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_MACROSECOND2
>>  
>>  #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 2a9db46d1ff9..64d167d18ae6 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_MS3
>> +// The delay is need for cpld and I2C. This is a empirical value. 
>> 

Re: [edk2] [PATCH edk2-platforms v2 06/15] Hisilicon/D06: Move some functions to OemMiscLib

2018-11-19 Thread Leif Lindholm
On Fri, Nov 16, 2018 at 02:56:53PM +0800, Ming Huang wrote:
> 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 

I did not see any of my review comments addressed, or any response
saying it was not being changed.

My feedback was:
---
This would be more clear as "platform specific" than "cpld relative".

I did not realise this wasn't a Hisilicon component when reviewing the
original set.

I approve of this change, but can you tell me why it is included in
this set? If the goal is to make the M41T83 support platform
independent, should the library also move to Silicon/ST/?
---

So could you please update the commit message, and add a subsequent
patch moving Library/M41T83RealTimeClockLib to
Silicon/STMicroelectronics (and updating D06.dsc to match)?
I do not care if it is not perfectly abstracted yet - we can deal with
that when we have other users of the component in the tree.

/
Leif

> ---
>  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(-)
> 
> diff --git 
> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
> index e0bf6b3f24db..4e963fd4531a 100644
> --- 
> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
> +++ 
> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
> @@ -27,7 +27,6 @@ [Sources.common]
>  [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 86ea6a1b3deb..0d7bf71b17d2 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 d985055d9bb6..f32910885856 100644
> --- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
> +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
> @@ -17,11 +17,7 @@
>  #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_MS3
> -// 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_MACROSECOND2
>  
>  #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 2a9db46d1ff9..64d167d18ae6 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_MS3
> +// The delay is need for cpld and I2C. This is a empirical value. 
> MemoryFence is no need.
> +#define RTC_DELAY_2_MACROSECOND2
>  
>  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 & 

[edk2] [PATCH edk2-platforms v2 06/15] Hisilicon/D06: Move some functions to OemMiscLib

2018-11-15 Thread Ming Huang
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(-)

diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
index e0bf6b3f24db..4e963fd4531a 100644
--- 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
+++ 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
@@ -27,7 +27,6 @@ [Sources.common]
 [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 86ea6a1b3deb..0d7bf71b17d2 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 d985055d9bb6..f32910885856 100644
--- a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -17,11 +17,7 @@
 #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_MS3
-// 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_MACROSECOND2
 
 #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 2a9db46d1ff9..64d167d18ae6 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_MS3
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_2_MACROSECOND2
 
 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)