diff --git a/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c b/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c index e26d5d774..e5b637015 100644 --- a/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c +++ b/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c @@ -638,12 +638,36 @@ static int pmu_handle_event(struct nvgpu_pmu *pmu, struct pmu_msg *msg) return err; } -static bool pmu_read_message(struct nvgpu_pmu *pmu, - struct nvgpu_falcon_queue *queue, - struct pmu_msg *msg, int *status) +static bool pmu_falcon_queue_read(struct nvgpu_pmu *pmu, + struct nvgpu_falcon_queue *queue, void *data, + u32 bytes_to_read, int *status) { struct gk20a *g = gk20a_from_pmu(pmu); - u32 read_size, bytes_read; + u32 bytes_read; + int err; + + err = nvgpu_falcon_queue_pop(pmu->flcn, queue, data, + bytes_to_read, &bytes_read); + if (err != 0) { + nvgpu_err(g, "fail to read msg: err %d", err); + *status = err; + return false; + } + if (bytes_read != bytes_to_read) { + nvgpu_err(g, "fail to read requested bytes: 0x%x != 0x%x", + bytes_to_read, bytes_read); + *status = -EINVAL; + return false; + } + + return true; +} + +static bool pmu_read_message(struct nvgpu_pmu *pmu, + struct nvgpu_falcon_queue *queue, struct pmu_msg *msg, int *status) +{ + struct gk20a *g = gk20a_from_pmu(pmu); + u32 read_size; u32 queue_id; int err; @@ -655,11 +679,9 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, queue_id = nvgpu_falcon_queue_get_id(queue); - err = nvgpu_falcon_queue_pop(pmu->flcn, queue, &msg->hdr, - PMU_MSG_HDR_SIZE, &bytes_read); - if (err != 0 || bytes_read != PMU_MSG_HDR_SIZE) { + if (!pmu_falcon_queue_read(pmu, queue, &msg->hdr, PMU_MSG_HDR_SIZE, + status)) { nvgpu_err(g, "fail to read msg from queue %d", queue_id); - *status = err | -EINVAL; goto clean_up; } @@ -667,16 +689,14 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, err = nvgpu_falcon_queue_rewind(pmu->flcn, queue); if (err != 0) { nvgpu_err(g, "fail to rewind queue %d", queue_id); - *status = err | -EINVAL; + *status = err; goto clean_up; } /* read again after rewind */ - err = nvgpu_falcon_queue_pop(pmu->flcn, queue, &msg->hdr, - PMU_MSG_HDR_SIZE, &bytes_read); - if (err != 0 || bytes_read != PMU_MSG_HDR_SIZE) { - nvgpu_err(g, - "fail to read msg from queue %d", queue_id); - *status = err | -EINVAL; + if (!pmu_falcon_queue_read(pmu, queue, &msg->hdr, + PMU_MSG_HDR_SIZE, status)) { + nvgpu_err(g, "fail to read msg from queue %d", + queue_id); goto clean_up; } } @@ -690,12 +710,10 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, if (msg->hdr.size > PMU_MSG_HDR_SIZE) { read_size = msg->hdr.size - PMU_MSG_HDR_SIZE; - err = nvgpu_falcon_queue_pop(pmu->flcn, queue, &msg->msg, - read_size, &bytes_read); - if (err != 0 || bytes_read != read_size) { - nvgpu_err(g, - "fail to read msg from queue %d", queue_id); - *status = err; + if (!pmu_falcon_queue_read(pmu, queue, &msg->msg, read_size, + status)) { + nvgpu_err(g, "fail to read msg from queue %d", + queue_id); goto clean_up; } } diff --git a/drivers/gpu/nvgpu/common/sec2/sec2_ipc.c b/drivers/gpu/nvgpu/common/sec2/sec2_ipc.c index 7e8181b0c..eacb25570 100644 --- a/drivers/gpu/nvgpu/common/sec2/sec2_ipc.c +++ b/drivers/gpu/nvgpu/common/sec2/sec2_ipc.c @@ -241,12 +241,37 @@ static int sec2_handle_event(struct nvgpu_sec2 *sec2, return err; } +static bool sec2_falcon_queue_read(struct nvgpu_sec2 *sec2, + struct nvgpu_falcon_queue *queue, void *data, + u32 bytes_to_read, int *status) +{ + struct gk20a *g = sec2->g; + u32 bytes_read; + int err; + + err = nvgpu_falcon_queue_pop(sec2->flcn, queue, data, + bytes_to_read, &bytes_read); + if (err != 0) { + nvgpu_err(g, "fail to read msg: err %d", err); + *status = err; + return false; + } + if (bytes_read != bytes_to_read) { + nvgpu_err(g, "fail to read requested bytes: 0x%x != 0x%x", + bytes_to_read, bytes_read); + *status = -EINVAL; + return false; + } + + return true; +} + static bool sec2_read_message(struct nvgpu_sec2 *sec2, struct nvgpu_falcon_queue *queue, struct nv_flcn_msg_sec2 *msg, int *status) { struct gk20a *g = sec2->g; - u32 read_size, bytes_read; + u32 read_size; u32 queue_id; int err; @@ -258,11 +283,9 @@ static bool sec2_read_message(struct nvgpu_sec2 *sec2, queue_id = nvgpu_falcon_queue_get_id(queue); - err = nvgpu_falcon_queue_pop(sec2->flcn, queue, &msg->hdr, - PMU_MSG_HDR_SIZE, &bytes_read); - if ((err != 0) || (bytes_read != PMU_MSG_HDR_SIZE)) { + if (!sec2_falcon_queue_read(sec2, queue, &msg->hdr, PMU_MSG_HDR_SIZE, + status)) { nvgpu_err(g, "fail to read msg from queue %d", queue_id); - *status = err | -EINVAL; goto clean_up; } @@ -270,17 +293,15 @@ static bool sec2_read_message(struct nvgpu_sec2 *sec2, err = nvgpu_falcon_queue_rewind(sec2->flcn, queue); if (err != 0) { nvgpu_err(g, "fail to rewind queue %d", queue_id); - *status = err | -EINVAL; + *status = err; goto clean_up; } /* read again after rewind */ - err = nvgpu_falcon_queue_pop(sec2->flcn, queue, &msg->hdr, - PMU_MSG_HDR_SIZE, &bytes_read); - if ((err != 0) || (bytes_read != PMU_MSG_HDR_SIZE)) { - nvgpu_err(g, - "fail to read msg from queue %d", queue_id); - *status = err | -EINVAL; + if (!sec2_falcon_queue_read(sec2, queue, &msg->hdr, + PMU_MSG_HDR_SIZE, status)) { + nvgpu_err(g, "fail to read msg from queue %d", + queue_id); goto clean_up; } } @@ -294,12 +315,10 @@ static bool sec2_read_message(struct nvgpu_sec2 *sec2, if (msg->hdr.size > PMU_MSG_HDR_SIZE) { read_size = msg->hdr.size - PMU_MSG_HDR_SIZE; - err = nvgpu_falcon_queue_pop(sec2->flcn, queue, &msg->msg, - read_size, &bytes_read); - if ((err != 0) || (bytes_read != read_size)) { - nvgpu_err(g, - "fail to read msg from queue %d", queue_id); - *status = err; + if (!sec2_falcon_queue_read(sec2, queue, &msg->msg, read_size, + status)) { + nvgpu_err(g, "fail to read msg from queue %d", + queue_id); goto clean_up; } }