diff options
author | Randall Spangler <rspangler@chromium.org> | 2014-07-29 14:47:47 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-07-30 03:09:59 +0000 |
commit | a528f892915c7a20768d49402f052f100f10501e (patch) | |
tree | ade355ebd605514c34b0c7bccb0badc615cbcd38 /common/host_command_master.c | |
parent | 4692a1387a492d5697ae12a7195eac6e1249fc6b (diff) | |
download | chrome-ec-a528f892915c7a20768d49402f052f100f10501e.tar.gz |
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 <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210401
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'common/host_command_master.c')
-rw-r--r-- | common/host_command_master.c | 34 |
1 files 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; |