From a528f892915c7a20768d49402f052f100f10501e Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 29 Jul 2014 14:47:47 -0700 Subject: Use mutex for EC->PD host commands Host commands can be generated by either the PDCMD task (in response to PD interrupts), or the HOSTCMD task (in response to passthru requests). Use a mutex to serialize access to the EC->PD interface. BUG=chrome-os-partner:30079 BRANCH=none TEST=Boot samus Change-Id: If65d5eb4bbef91e6c811a06ea2e1487e17143dc7 Signed-off-by: Randall Spangler Reviewed-on: https://chromium-review.googlesource.com/210401 Reviewed-by: Bill Richardson Reviewed-by: Alec Berg --- common/host_command_master.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/common/host_command_master.c b/common/host_command_master.c index 23441d0a3a..15748d4e82 100644 --- a/common/host_command_master.c +++ b/common/host_command_master.c @@ -9,6 +9,7 @@ #include "console.h" #include "host_command.h" #include "i2c.h" +#include "task.h" #include "timer.h" #include "util.h" @@ -19,14 +20,16 @@ /* Host command timeout */ #define HOST_COMMAND_TIMEOUT_US SECOND -/* - * Sends a command to the PD (protocol v3). +static struct mutex pd_mutex; + +/** + * Non-task-safe internal version of pd_host_command(). * - * Returns >= 0 for success, or negative if error. + * Do not call this version directly! Use pd_host_command(). */ -int pd_host_command(int command, int version, - const void *outdata, int outsize, - void *indata, int insize) +static int pd_host_command_internal(int command, int version, + const void *outdata, int outsize, + void *indata, int insize) { int ret, i; int resp_len; @@ -149,6 +152,25 @@ int pd_host_command(int command, int version, return resp_len; } +int pd_host_command(int command, int version, + const void *outdata, int outsize, + void *indata, int insize) +{ + int rv; + + /* Acquire mutex */ + mutex_lock(&pd_mutex); + + /* Call internal version of host command */ + rv = pd_host_command_internal(command, version, outdata, outsize, + indata, insize); + + /* Release mutex */ + mutex_unlock(&pd_mutex); + + return rv; +} + static int command_pd_mcu(int argc, char **argv) { char *e; -- cgit v1.2.1