From: Pankaj Bansal <pankaj.ban...@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 unrecovered 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 preempt this. with this solution no timeout has been
observed so far.

Signed-off-by: Pankaj Bansal <pankaj.ban...@nxp.com>
---
 Silicon/NXP/Drivers/I2cDxe/I2cDxe.c   | 12 ++++++++++++
 Silicon/NXP/Drivers/I2cDxe/I2cDxe.inf |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

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;
 }
 
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 @@ [Defines]
   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 @@ [LibraryClasses]
   UefiBootServicesTableLib
   UefiDriverEntryPoint
   UefiLib
+  UefiRuntimeLib
 
 [Guids]
   gNxpNonDiscoverableI2cMasterGuid
-- 
2.17.1


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

View/Reply Online (#55997): https://edk2.groups.io/g/devel/message/55997
Mute This Topic: https://groups.io/mt/72077424/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to