summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-06-08 10:49:39 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-06-08 14:01:38 -0500
commit63657a69627ca1dbd10fb683a8096ab2e8e77f2b (patch)
treef5aa6875dfbdd887c52541c779ff275596ad8f6d /src/lib
parent74b9b31c9ae811dd527d4eb328e9fa93327442ab (diff)
downloadtalos-hostboot-63657a69627ca1dbd10fb683a8096ab2e8e77f2b.tar.gz
talos-hostboot-63657a69627ca1dbd10fb683a8096ab2e8e77f2b.zip
Create per-CPU mutex for XSCOM usage.
Change-Id: I76ad5c1d553d544b52910afd82e2716781ea13b9 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/140 Tested-by: Jenkins Server Reviewed-by: Thi N. Tran <thi@us.ibm.com> Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/syscall_mmio.C35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib/syscall_mmio.C b/src/lib/syscall_mmio.C
index 30ec5bd37..83498798b 100644
--- a/src/lib/syscall_mmio.C
+++ b/src/lib/syscall_mmio.C
@@ -1,5 +1,8 @@
#include <sys/syscall.h>
#include <sys/mmio.h>
+#include <assert.h>
+#include <kernel/task.H>
+#include <kernel/cpu.H>
using namespace Systemcalls;
@@ -22,3 +25,35 @@ int mmio_hmer_write(uint64_t value)
{
return (int)(int64_t)_syscall1(MMIO_HMER_WRITE, (void*)value);
}
+
+mutex_t mmio_xscom_mutex()
+{
+ // Get task structure.
+ register task_t* task;
+ asm volatile("mr %0, 13" : "=r"(task));
+
+ // Ensure task is pinned.
+ assert(task->affinity_pinned);
+
+ // Get mutex from cpu structure.
+ mutex_t mutex = task->cpu->xscom_mutex;
+
+ // Create mutex if not created.
+ if (NULL == mutex)
+ {
+ mutex = mutex_create();
+
+ // Atomically update xscom_mutex with new mutex.
+ if (!__sync_bool_compare_and_swap(&task->cpu->xscom_mutex, NULL, mutex))
+ {
+ // Failed, some other thread beat us to it.
+
+ // Destroy mutex and get one created by other thread in the
+ // meantime.
+ mutex_destroy(mutex);
+ mutex = task->cpu->xscom_mutex;
+ }
+ }
+
+ return mutex;
+}
OpenPOWER on IntegriCloud