In order to optimize performance, limit amount of back and forth
transactions between x86 and PSP. This is done by introduction of
cooldown period - that is window in which x86 isn't releasing the bus
immediately after each I2C transaction.
In order to protect PSP from being starved while waiting for
arbitration, after a programmed time bus is automatically released by a
deferred function.
Signed-off-by: Jan Dabros <jsd@xxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-designware-amdpsp.c | 68 +++++++++++++++++-----
1 file changed, 53 insertions(+), 15 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index b624356c945f..2e1bb5ae72c3 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -6,6 +6,7 @@
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/psp-sev.h>
#include <linux/types.h>
+#include <linux/workqueue.h>
#include <asm/msr.h>
@@ -15,6 +16,8 @@
#define PSP_MBOX_OFFSET 0x10570
#define PSP_CMD_TIMEOUT_US (500 * USEC_PER_MSEC)
+#define PSP_I2C_COOLDOWN_TIME_MS 100
+
+static void release_bus_now(void)
+static void psp_release_i2c_bus_deferred(struct work_struct *work)
+static DECLARE_DELAYED_WORK(release_queue, psp_release_i2c_bus_deferred);
+
+ /*
+ * Send a release command to PSP if the cooldown timeout elapsed but x86 still
+ * owns the ctrlr.
+ */