scmi: Optimize bakery locks when HW_ASSISTED_COHERENCY is enabled

When HW_ASSISTED_COHERENCY is enabled we can use spinlocks
instead of using the more complex and slower bakery algorithm.

Change-Id: I9d791a70050d599241169b9160a67e57d5506564
Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
diff --git a/plat/arm/css/drivers/scmi/scmi.h b/plat/arm/css/drivers/scmi/scmi.h
index 723fd06..71a8c2d 100644
--- a/plat/arm/css/drivers/scmi/scmi.h
+++ b/plat/arm/css/drivers/scmi/scmi.h
@@ -10,6 +10,7 @@
 #include <bakery_lock.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <spinlock.h>
 
 /* Supported SCMI Protocol Versions */
 #define SCMI_AP_CORE_PROTO_VER			MAKE_SCMI_VERSION(1, 0)
@@ -116,13 +117,20 @@
 	void *cookie;
 } scmi_channel_plat_info_t;
 
+
+#if HW_ASSISTED_COHERENCY
+typedef spinlock_t scmi_lock_t;
+#else
+typedef bakery_lock_t scmi_lock_t;
+#endif
+
 /*
  * Structure to represent an SCMI channel.
  */
 typedef struct scmi_channel {
 	scmi_channel_plat_info_t *info;
 	 /* The lock for channel access */
-	bakery_lock_t *lock;
+	scmi_lock_t *lock;
 	/* Indicate whether the channel is initialized */
 	int is_initialized;
 } scmi_channel_t;
diff --git a/plat/arm/css/drivers/scmi/scmi_common.c b/plat/arm/css/drivers/scmi/scmi_common.c
index 8482d21..b34178e 100644
--- a/plat/arm/css/drivers/scmi/scmi_common.c
+++ b/plat/arm/css/drivers/scmi/scmi_common.c
@@ -10,13 +10,25 @@
 #include "scmi.h"
 #include "scmi_private.h"
 
+
+#if HW_ASSISTED_COHERENCY
+#define scmi_lock_init(lock)
+#define scmi_lock_get(lock)		spin_lock(lock)
+#define scmi_lock_release(lock)		spin_unlock(lock)
+#else
+#define scmi_lock_init(lock)		bakery_lock_init(lock)
+#define scmi_lock_get(lock)		bakery_lock_get(lock)
+#define scmi_lock_release(lock)		bakery_lock_release(lock)
+#endif
+
+
 /*
  * Private helper function to get exclusive access to SCMI channel.
  */
 void scmi_get_channel(scmi_channel_t *ch)
 {
 	assert(ch->lock);
-	bakery_lock_get(ch->lock);
+	scmi_lock_get(ch->lock);
 
 	/* Make sure any previous command has finished */
 	assert(SCMI_IS_CHANNEL_FREE(
@@ -68,7 +80,7 @@
 			((mailbox_mem_t *)(ch->info->scmi_mbx_mem))->status));
 
 	assert(ch->lock);
-	bakery_lock_release(ch->lock);
+	scmi_lock_release(ch->lock);
 }
 
 /*
@@ -152,7 +164,7 @@
 
 	assert(ch->lock);
 
-	bakery_lock_init(ch->lock);
+	scmi_lock_init(ch->lock);
 
 	ch->is_initialized = 1;