[edk2-devel] [PATCH edk2-platforms v4 03/24] Silicon/NXP/I2cDxe: Fix I2c Timeout with RTC

Pankaj Bansal pankaj.bansal at nxp.com
Fri May 1 05:49:34 UTC 2020


From: Pankaj Bansal <pankaj.bansal at nxp.com>

With latest edk2 codebase, sometimes i2c timeout is observed when
Network devices are being probed.
This is happening when gRT->GetTime request is ongoing.
gRT->GetTime triggers a read request to Real Time Clock which is
connected to I2c bus.
In between read request, if an event occurs, which also triggers
gRT->GetTime (i.e. RTC read), the I2c bus goes into unrecoverable state.

This state is not even recovered, when rebooting the board.
We need to power off the board completely to recover i2c bus.

To prevent this, TPL level of I2c read is being raised to high, so that
no other event can pre-empt this. with this solution no timeout has been
observed so far.

Signed-off-by: Pankaj Bansal <pankaj.bansal at nxp.com>
Reviewed-by: Leif Lindholm <leif at nuviainc.com>
---

Notes:
    V4:
    - No change
    
    V3:
    - No change

 Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf |  3 ++-
 Silicon/NXP/Drivers/I2cDxe/I2cDxe.c   | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf b/Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf
index 84adb837c249..867376044656 100644
--- a/Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf
+++ b/Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf
@@ -13,7 +13,7 @@
   INF_VERSION                    = 0x0001001A
   BASE_NAME                      = I2cDxe
   FILE_GUID                      = 5f2927ba-1b04-4d5f-8bef-2b50c635d1e7
-  MODULE_TYPE                    = DXE_DRIVER
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER
   VERSION_STRING                 = 1.0
   ENTRY_POINT                    = I2cDxeEntryPoint
   UNLOAD                         = I2cDxeUnload
@@ -36,6 +36,7 @@
   UefiBootServicesTableLib
   UefiDriverEntryPoint
   UefiLib
+  UefiRuntimeLib
 
 [Guids]
   gNxpNonDiscoverableI2cMasterGuid
diff --git a/Silicon/NXP/Drivers/I2cDxe/I2cDxe.c b/Silicon/NXP/Drivers/I2cDxe/I2cDxe.c
index 848e707c1673..a5aba47b3ed4 100644
--- a/Silicon/NXP/Drivers/I2cDxe/I2cDxe.c
+++ b/Silicon/NXP/Drivers/I2cDxe/I2cDxe.c
@@ -16,6 +16,7 @@
 #include <Library/TimerLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiLib.h>
+#include <Library/UefiRuntimeLib.h>
 
 #include "I2cDxe.h"
 
@@ -88,6 +89,13 @@ StartRequest (
   NXP_I2C_MASTER           *I2c;
   UINTN                    I2cBase;
   EFI_STATUS               Status;
+  EFI_TPL                  Tpl;
+  BOOLEAN                  AtRuntime;
+
+  AtRuntime = EfiAtRuntime ();
+  if (!AtRuntime) {
+    Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
+  }
 
   I2c = NXP_I2C_FROM_THIS (This);
 
@@ -95,6 +103,10 @@ StartRequest (
 
   Status = I2cBusXfer (I2cBase, SlaveAddress, RequestPacket);
 
+  if (!AtRuntime) {
+    gBS->RestoreTPL (Tpl);
+  }
+
   return Status;
 }
 
-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#58370): https://edk2.groups.io/g/devel/message/58370
Mute This Topic: https://groups.io/mt/73370121/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list