summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoberto Pereira <rpere@google.com>2017-11-02 15:09:20 -0700
committerfaqiang.zhu <faqiang.zhu@nxp.com>2018-11-12 09:18:35 +0800
commitdfd911856d31fd91eb4e3c1edb1d691723c6edaf (patch)
tree98162b12045fc356216cbdb5075f6c3a3defa100 /lib
parentf7d43073b350f88c79ed966c7e84d01a90cbad8c (diff)
ql-tipc: trusty_ipc: Change ipc polling to be per device
This allows ipc devices to provide service callbacks (e.g. rpmb) transparently to the application instead of needing to have prior knowledge of the expected request and having to poll the individual services' channels separately. Change-Id: I3257ae5e429f4a0c279f070d750b56c5600c38d5
Diffstat (limited to 'lib')
-rw-r--r--lib/trusty/ql-tipc/avb.c31
-rw-r--r--lib/trusty/ql-tipc/ipc.c35
-rw-r--r--lib/trusty/ql-tipc/keymaster.c26
-rw-r--r--lib/trusty/ql-tipc/rpmb_proxy.c33
4 files changed, 52 insertions, 73 deletions
diff --git a/lib/trusty/ql-tipc/avb.c b/lib/trusty/ql-tipc/avb.c
index ebbb38ff20..2f2a418a44 100644
--- a/lib/trusty/ql-tipc/avb.c
+++ b/lib/trusty/ql-tipc/avb.c
@@ -75,10 +75,9 @@ static int avb_read_response(struct avb_message *msg, uint32_t cmd, void *resp,
* @resp: the response buffer
* @resp_size_p: pointer to the size of the response buffer. changed to the
actual size of the response read from the secure side
- * @handle_rpmb: true if the request is expected to invoke RPMB callbacks
*/
static int avb_do_tipc(uint32_t cmd, void *req, uint32_t req_size, void *resp,
- uint32_t *resp_size_p, bool handle_rpmb)
+ uint32_t *resp_size_p)
{
int rc;
struct avb_message msg = { .cmd = cmd };
@@ -94,16 +93,6 @@ static int avb_do_tipc(uint32_t cmd, void *req, uint32_t req_size, void *resp,
return rc;
}
- if (handle_rpmb) {
- /* handle any incoming RPMB requests */
- rc = rpmb_storage_proxy_poll();
- if (rc < 0) {
- trusty_error("%s: failed (%d) to get RPMB requests\n", __func__,
- rc);
- return rc;
- }
- }
-
uint32_t resp_size = resp_size_p ? *resp_size_p : 0;
rc = avb_read_response(&msg, cmd, resp, resp_size);
if (rc < 0) {
@@ -128,7 +117,7 @@ static int avb_get_version(uint32_t *version)
struct avb_get_version_resp resp;
uint32_t resp_size = sizeof(resp);
- rc = avb_do_tipc(AVB_GET_VERSION, NULL, 0, &resp, &resp_size, false);
+ rc = avb_do_tipc(AVB_GET_VERSION, NULL, 0, &resp, &resp_size);
*version = resp.version;
return rc;
@@ -190,7 +179,7 @@ int trusty_read_rollback_index(uint32_t slot, uint64_t *value)
uint32_t resp_size = sizeof(resp);
rc = avb_do_tipc(READ_ROLLBACK_INDEX, &req, sizeof(req), &resp,
- &resp_size, true);
+ &resp_size);
*value = resp.value;
return rc;
@@ -204,7 +193,7 @@ int trusty_write_rollback_index(uint32_t slot, uint64_t value)
uint32_t resp_size = sizeof(resp);
rc = avb_do_tipc(WRITE_ROLLBACK_INDEX, &req, sizeof(req), &resp,
- &resp_size, true);
+ &resp_size);
return rc;
}
@@ -213,7 +202,7 @@ int trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size)
uint8_t resp_buf[AVB_MAX_BUFFER_LENGTH];
uint32_t resp_size = AVB_MAX_BUFFER_LENGTH;
int rc = avb_do_tipc(READ_PERMANENT_ATTRIBUTES, NULL, 0, resp_buf,
- &resp_size, true);
+ &resp_size);
if (rc != 0) {
return rc;
}
@@ -227,24 +216,24 @@ int trusty_read_permanent_attributes(uint8_t *attributes, uint32_t size)
int trusty_write_permanent_attributes(uint8_t *attributes, uint32_t size)
{
- return avb_do_tipc(WRITE_PERMANENT_ATTRIBUTES, attributes, size, NULL, NULL,
- true);
+ return avb_do_tipc(WRITE_PERMANENT_ATTRIBUTES, attributes, size, NULL,
+ NULL);
}
int trusty_read_lock_state(uint8_t *lock_state)
{
uint32_t resp_size = sizeof(*lock_state);
return avb_do_tipc(READ_LOCK_STATE, NULL, 0, lock_state,
- &resp_size, true);
+ &resp_size);
}
int trusty_write_lock_state(uint8_t lock_state)
{
return avb_do_tipc(WRITE_LOCK_STATE, &lock_state, sizeof(lock_state), NULL,
- NULL, true);
+ NULL);
}
int trusty_lock_boot_state(void)
{
- return avb_do_tipc(LOCK_BOOT_STATE, NULL, 0, NULL, NULL, false);
+ return avb_do_tipc(LOCK_BOOT_STATE, NULL, 0, NULL, NULL);
}
diff --git a/lib/trusty/ql-tipc/ipc.c b/lib/trusty/ql-tipc/ipc.c
index 95c0ee605c..f488984d76 100644
--- a/lib/trusty/ql-tipc/ipc.c
+++ b/lib/trusty/ql-tipc/ipc.c
@@ -57,14 +57,15 @@ static int wait_for_complete(struct trusty_ipc_chan *chan)
chan->complete = 0;
for (;;) {
- rc = trusty_ipc_poll_for_event(chan);
+ rc = trusty_ipc_poll_for_event(chan->dev);
if (rc < 0)
return rc;
if (chan->complete)
break;
- trusty_ipc_dev_idle(chan->dev);
+ if (rc == TRUSTY_EVENT_NONE)
+ trusty_ipc_dev_idle(chan->dev);
}
return chan->complete;
@@ -185,29 +186,30 @@ int trusty_ipc_recv(struct trusty_ipc_chan *chan,
trusty_assert(chan->dev);
trusty_assert(chan->handle);
-Again:
- rc = trusty_ipc_dev_recv(chan->dev, chan->handle, iovs, iovs_cnt);
- if (rc == TRUSTY_ERR_NO_MSG) {
- if (wait) {
- rc = wait_for_reply(chan);
- if (rc < 0) {
- trusty_error("%s: wait to reply failed (%d)\n", __func__, rc);
- return rc;
- }
- goto Again;
+ if (wait) {
+ rc = wait_for_reply(chan);
+ if (rc < 0) {
+ trusty_error("%s: wait to reply failed (%d)\n", __func__, rc);
+ return rc;
}
}
+ rc = trusty_ipc_dev_recv(chan->dev, chan->handle, iovs, iovs_cnt);
+ if (rc < 0)
+ trusty_error("%s: ipc recv failed (%d)\n", __func__, rc);
+
return rc;
}
-int trusty_ipc_poll_for_event(struct trusty_ipc_chan *chan)
+int trusty_ipc_poll_for_event(struct trusty_ipc_dev *ipc_dev)
{
int rc;
struct trusty_ipc_event evt;
- trusty_assert(chan && chan->ops);
+ struct trusty_ipc_chan *chan;
- rc = trusty_ipc_dev_get_event(chan->dev, chan->handle, &evt);
+ trusty_assert(dev);
+
+ rc = trusty_ipc_dev_get_event(ipc_dev, 0, &evt);
if (rc) {
trusty_error("%s: get event failed (%d)\n", __func__, rc);
return rc;
@@ -219,6 +221,9 @@ int trusty_ipc_poll_for_event(struct trusty_ipc_chan *chan)
return TRUSTY_EVENT_NONE;
}
+ chan = (struct trusty_ipc_chan *)(uintptr_t)evt.cookie;
+ trusty_assert(chan && chan->ops);
+
/* check if we have raw event handler */
if (chan->ops->on_raw_event) {
/* invoke it first */
diff --git a/lib/trusty/ql-tipc/keymaster.c b/lib/trusty/ql-tipc/keymaster.c
index 2c241018b7..21e0e6cf4b 100644
--- a/lib/trusty/ql-tipc/keymaster.c
+++ b/lib/trusty/ql-tipc/keymaster.c
@@ -185,9 +185,8 @@ static int km_read_data_response(uint32_t cmd, int32_t *error,
* caller expects an additional data buffer to be returned from the secure
* side.
*/
-static int km_do_tipc(uint32_t cmd, bool handle_rpmb, void* req,
- uint32_t req_len, void* resp_data,
- uint32_t* resp_data_len)
+static int km_do_tipc(uint32_t cmd, void* req, uint32_t req_len,
+ void* resp_data, uint32_t* resp_data_len)
{
int rc = TRUSTY_ERR_GENERIC;
struct km_no_response resp_header;
@@ -198,15 +197,6 @@ static int km_do_tipc(uint32_t cmd, bool handle_rpmb, void* req,
return rc;
}
- if (handle_rpmb) {
- /* handle any incoming RPMB requests */
- rc = rpmb_storage_proxy_poll();
- if (rc < 0) {
- trusty_error("%s: failed (%d) to get RPMB requests\n", __func__, rc);
- return rc;
- }
- }
-
if (!resp_data) {
rc = km_read_raw_response(cmd, &resp_header, sizeof(resp_header));
} else {
@@ -343,7 +333,7 @@ int trusty_set_boot_params(uint32_t os_version, uint32_t os_patchlevel,
trusty_error("failed (%d) to serialize request\n", rc);
goto end;
}
- rc = km_do_tipc(KM_SET_BOOT_PARAMS, false, req, req_size, NULL, NULL);
+ rc = km_do_tipc(KM_SET_BOOT_PARAMS, req, req_size, NULL, NULL);
end:
if (req) {
@@ -369,7 +359,7 @@ static int trusty_send_attestation_data(uint32_t cmd, const uint8_t *data,
trusty_error("failed (%d) to serialize request\n", rc);
goto end;
}
- rc = km_do_tipc(cmd, true, req, req_size, NULL, NULL);
+ rc = km_do_tipc(cmd, req, req_size, NULL, NULL);
end:
if (req) {
@@ -393,7 +383,7 @@ static int trusty_send_raw_buffer(uint32_t cmd, const uint8_t *req_data,
trusty_error("failed (%d) to serialize request\n", rc);
goto end;
}
- rc = km_do_tipc(cmd, false, req, req_size, resp_data, resp_data_size);
+ rc = km_do_tipc(cmd, req, req_size, resp_data, resp_data_size);
end:
if (req) {
@@ -445,7 +435,7 @@ int trusty_atap_set_ca_response(const uint8_t *ca_response,
/* Tell the Trusty Keymaster TA the size of CA Response message */
begin_req.ca_response_size = ca_response_size;
- rc = km_do_tipc(KM_ATAP_SET_CA_RESPONSE_BEGIN, false, &begin_req,
+ rc = km_do_tipc(KM_ATAP_SET_CA_RESPONSE_BEGIN, &begin_req,
sizeof(begin_req), NULL, NULL);
if (rc != TRUSTY_ERR_NONE) {
return rc;
@@ -464,7 +454,7 @@ int trusty_atap_set_ca_response(const uint8_t *ca_response,
}
/* Tell Trusty Keymaster to parse the CA Response message */
- return km_do_tipc(KM_ATAP_SET_CA_RESPONSE_FINISH, true, NULL, 0, NULL, NULL);
+ return km_do_tipc(KM_ATAP_SET_CA_RESPONSE_FINISH, NULL, 0, NULL, NULL);
}
@@ -473,7 +463,7 @@ int trusty_atap_read_uuid_str(char **uuid_p)
*uuid_p = (char*) trusty_calloc(1, kUuidSize);
uint32_t response_size = kUuidSize;
- int rc = km_do_tipc(KM_ATAP_READ_UUID, true, NULL, 0, *uuid_p,
+ int rc = km_do_tipc(KM_ATAP_READ_UUID, NULL, 0, *uuid_p,
&response_size);
if (rc < 0) {
trusty_error("failed to read uuid: %d\n", rc);
diff --git a/lib/trusty/ql-tipc/rpmb_proxy.c b/lib/trusty/ql-tipc/rpmb_proxy.c
index 835e8634c9..812dc81720 100644
--- a/lib/trusty/ql-tipc/rpmb_proxy.c
+++ b/lib/trusty/ql-tipc/rpmb_proxy.c
@@ -300,35 +300,30 @@ int rpmb_storage_proxy_init(struct trusty_ipc_dev *dev, void *rpmb_dev)
/* override default ops */
proxy_chan.ops = &proxy_ops;
- rc = rpmb_storage_proxy_poll();
- if (rc < 0) {
- return rc;
- }
-
- /* mark as initialized */
- initialized = true;
-
- return TRUSTY_ERR_NONE;
-}
-
-int rpmb_storage_proxy_poll(void)
-{
- int rc = 0;
- while ((rc != TRUSTY_EVENT_NONE) && (proxy_chan.handle != INVALID_IPC_HANDLE)){
+ do {
/* Check for RPMB events */
- rc = trusty_ipc_poll_for_event(&proxy_chan);
+ rc = trusty_ipc_poll_for_event(proxy_chan.dev);
if (rc < 0) {
trusty_error("%s: failed (%d) to get rpmb event\n", __func__, rc);
return rc;
}
+
+ if (proxy_chan.handle == INVALID_IPC_HANDLE) {
+ trusty_error("%s: unexpected proxy channel close\n");
+ return TRUSTY_ERR_CHANNEL_CLOSED;
+ }
}
- return (proxy_chan.handle)? TRUSTY_ERR_NONE : TRUSTY_ERR_CHANNEL_CLOSED;
+ while (rc != TRUSTY_EVENT_NONE);
+
+ /* mark as initialized */
+ initialized = true;
+
+ return TRUSTY_ERR_NONE;
}
void rpmb_storage_proxy_shutdown(struct trusty_ipc_dev *dev)
{
- if (!initialized)
- return; /* nothing to do */
+ trusty_assert(initialized);
/* close channel */
trusty_ipc_close(&proxy_chan);