From 2d454db04fcc0c03e05b4665831e5780240d79b8 Mon Sep 17 00:00:00 2001 From: Mahantesh Kumbar Date: Wed, 11 Jul 2018 15:00:45 +0530 Subject: gpu: nvgpu: falcon queue support -Renamed "struct pmu_queue" to "struct nvgpu_falcon_queue" & moved to falcon.h -Renamed pmu_queue_* functions to flcn_queue_* & moved to new file falcon_queue.c -Created ops for queue functions in struct nvgpu_falcon_queue to support different queue types like DMEM/FB-Q. -Created ops in nvgpu_falcon_engine_dependency_ops to add engine specific queue functionality & assigned correct HAL functions in hal*.c file. -Made changes in dependent functions as needed to replace struct pmu_queue & calling queue functions using nvgpu_falcon_queue data structure. -Replaced input param "struct nvgpu_pmu *pmu" with "struct gk20a *g" for pmu ops pmu_queue_head/pmu_queue_tail & also for functions gk20a_pmu_queue_head()/ gk20a_pmu_queue_tail(). -Made changes in nvgpu_pmu_queue_init() to use nvgpu_falcon_queue for PMU queue. -Modified Makefile to include falcon_queue.o -Modified Makefile.sources to include falcon_queue.c Change-Id: I956328f6631b7154267fd5a29eaa1826190d99d1 Signed-off-by: Mahantesh Kumbar Reviewed-on: https://git-master.nvidia.com/r/1776070 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/falcon/falcon_queue.c | 422 +++++++++++++++++++++++++ drivers/gpu/nvgpu/common/pmu/pmu.c | 5 +- drivers/gpu/nvgpu/common/pmu/pmu_fw.c | 12 +- drivers/gpu/nvgpu/common/pmu/pmu_ipc.c | 353 +++------------------ 4 files changed, 481 insertions(+), 311 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/falcon/falcon_queue.c (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/falcon/falcon_queue.c b/drivers/gpu/nvgpu/common/falcon/falcon_queue.c new file mode 100644 index 00000000..6834821c --- /dev/null +++ b/drivers/gpu/nvgpu/common/falcon/falcon_queue.c @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include + +/* DMEM-Q specific ops */ +static int flcn_queue_head_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, u32 *head, bool set) +{ + int err = -ENOSYS; + + if (flcn->flcn_engine_dep_ops.queue_head != NULL) { + err = flcn->flcn_engine_dep_ops.queue_head(flcn->g, queue, + head, set); + } + + return err; +} + +static int flcn_queue_tail_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, u32 *tail, bool set) +{ + int err = -ENOSYS; + + if (flcn->flcn_engine_dep_ops.queue_tail != NULL) { + err = flcn->flcn_engine_dep_ops.queue_tail(flcn->g, queue, + tail, set); + } + + return err; +} + +static bool flcn_queue_has_room_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, u32 size, bool *need_rewind) +{ + u32 q_head = 0; + u32 q_tail = 0; + u32 q_free = 0; + bool q_rewind = false; + int err = 0; + + size = ALIGN(size, QUEUE_ALIGNMENT); + + err = queue->head(flcn, queue, &q_head, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "queue head GET failed"); + goto exit; + } + + err = queue->tail(flcn, queue, &q_tail, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "queue tail GET failed"); + goto exit; + } + + if (q_head >= q_tail) { + q_free = queue->offset + queue->size - q_head; + q_free -= (u32)PMU_CMD_HDR_SIZE; + + if (size > q_free) { + q_rewind = true; + q_head = queue->offset; + } + } + + if (q_head < q_tail) { + q_free = q_tail - q_head - 1U; + } + + if (need_rewind != NULL) { + *need_rewind = q_rewind; + } + +exit: + return size <= q_free; +} + +static int flcn_queue_push_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, void *data, u32 size) +{ + int err = 0; + + err = nvgpu_flcn_copy_to_dmem(flcn, queue->position, data, size, 0); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d, queue-%d", flcn->flcn_id, + queue->id); + nvgpu_err(flcn->g, "dmem queue write failed"); + goto exit; + } + + queue->position += ALIGN(size, QUEUE_ALIGNMENT); + +exit: + return err; +} + +static int flcn_queue_pop_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, void *data, u32 size, + u32 *bytes_read) +{ + struct gk20a *g = flcn->g; + u32 q_tail = queue->position; + u32 q_head = 0; + u32 used = 0; + int err = 0; + + *bytes_read = 0; + + err = queue->head(flcn, queue, &q_head, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d, queue-%d, head GET failed", + flcn->flcn_id, queue->id); + goto exit; + } + + if (q_head == q_tail) { + goto exit; + } else if (q_head > q_tail) { + used = q_head - q_tail; + } else { + used = queue->offset + queue->size - q_tail; + } + + if (size > used) { + nvgpu_warn(g, "queue size smaller than request read"); + size = used; + } + + err = nvgpu_flcn_copy_from_dmem(flcn, q_tail, data, size, 0); + if (err != 0) { + nvgpu_err(g, "flcn-%d, queue-%d", flcn->flcn_id, + queue->id); + nvgpu_err(flcn->g, "dmem queue read failed"); + goto exit; + } + + queue->position += ALIGN(size, QUEUE_ALIGNMENT); + *bytes_read = size; + +exit: + return err; +} + +static int flcn_queue_rewind_dmem(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + struct gk20a *g = flcn->g; + struct pmu_cmd cmd; + int err = 0; + + if (queue->oflag == OFLAG_WRITE) { + cmd.hdr.unit_id = PMU_UNIT_REWIND; + cmd.hdr.size = (u8)PMU_CMD_HDR_SIZE; + err = queue->push(flcn, queue, &cmd, cmd.hdr.size); + if (err != 0) { + nvgpu_err(g, "flcn-%d queue-%d, rewind request failed", + flcn->flcn_id, queue->id); + goto exit; + } else { + nvgpu_pmu_dbg(g, "flcn-%d queue-%d, rewinded", + flcn->flcn_id, queue->id); + } + } + + /* update queue position */ + queue->position = queue->offset; + + if (queue->oflag == OFLAG_READ) { + err = queue->tail(flcn, queue, &queue->position, + QUEUE_SET); + if (err != 0){ + nvgpu_err(flcn->g, "flcn-%d queue-%d, position SET failed", + flcn->flcn_id, queue->id); + goto exit; + } + } + +exit: + return err; +} + +/* assign DMEM queue type specific ops */ +static void flcn_queue_init_dmem_queue(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + queue->head = flcn_queue_head_dmem; + queue->tail = flcn_queue_tail_dmem; + queue->has_room = flcn_queue_has_room_dmem; + queue->push = flcn_queue_push_dmem; + queue->pop = flcn_queue_pop_dmem; + queue->rewind = flcn_queue_rewind_dmem; +} + +static int flcn_queue_prepare_write(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, u32 size) +{ + bool q_rewind = false; + int err = 0; + + /* make sure there's enough free space for the write */ + if (!queue->has_room(flcn, queue, size, &q_rewind)) { + nvgpu_pmu_dbg(flcn->g, "queue full: queue-id %d: index %d", + queue->id, queue->index); + err = -EAGAIN; + goto exit; + } + + err = queue->head(flcn, queue, &queue->position, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, position GET failed", + flcn->flcn_id, queue->id); + goto exit; + } + + if (q_rewind) { + err = queue->rewind(flcn, queue); + } + +exit: + return err; +} + +/* queue public functions */ + +/* queue push operation with lock */ +int nvgpu_flcn_queue_push(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, void *data, u32 size) +{ + int err = 0; + + if (queue->oflag != OFLAG_WRITE) { + nvgpu_err(flcn->g, "flcn-%d, queue-%d not opened for write", + flcn->flcn_id, queue->id); + err = -EINVAL; + goto exit; + } + + /* acquire mutex */ + nvgpu_mutex_acquire(&queue->mutex); + + err = flcn_queue_prepare_write(flcn, queue, size); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, fail to open", + flcn->flcn_id, queue->id); + goto unlock_mutex; + } + + err = queue->push(flcn, queue, data, size); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, fail to write", + flcn->flcn_id, queue->id); + } + + err = queue->head(flcn, queue, &queue->position, QUEUE_SET); + if (err != 0){ + nvgpu_err(flcn->g, "flcn-%d queue-%d, position SET failed", + flcn->flcn_id, queue->id); + } + +unlock_mutex: + /* release mutex */ + nvgpu_mutex_release(&queue->mutex); +exit: + return err; +} + +/* queue pop operation with lock */ +int nvgpu_flcn_queue_pop(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue, void *data, u32 size, + u32 *bytes_read) +{ + int err = 0; + + if (queue->oflag != OFLAG_READ) { + nvgpu_err(flcn->g, "flcn-%d, queue-%d, not opened for read", + flcn->flcn_id, queue->id); + err = -EINVAL; + goto exit; + } + + /* acquire mutex */ + nvgpu_mutex_acquire(&queue->mutex); + + err = queue->tail(flcn, queue, &queue->position, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, position GET failed", + flcn->flcn_id, queue->id); + goto unlock_mutex; + } + + err = queue->pop(flcn, queue, data, size, bytes_read); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, fail to read", + flcn->flcn_id, queue->id); + } + + err = queue->tail(flcn, queue, &queue->position, QUEUE_SET); + if (err != 0){ + nvgpu_err(flcn->g, "flcn-%d queue-%d, position SET failed", + flcn->flcn_id, queue->id); + } + +unlock_mutex: + /* release mutex */ + nvgpu_mutex_release(&queue->mutex); +exit: + return err; +} + +int nvgpu_flcn_queue_rewind(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + int err = 0; + + /* acquire mutex */ + nvgpu_mutex_acquire(&queue->mutex); + + if (queue->rewind != NULL) { + err = queue->rewind(flcn, queue); + } + + /* release mutex */ + nvgpu_mutex_release(&queue->mutex); + + return err; +} + +/* queue is_empty check with lock */ +bool nvgpu_flcn_queue_is_empty(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + u32 q_head = 0; + u32 q_tail = 0; + int err = 0; + + /* acquire mutex */ + nvgpu_mutex_acquire(&queue->mutex); + + err = queue->head(flcn, queue, &q_head, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, head GET failed", + flcn->flcn_id, queue->id); + goto exit; + } + + err = queue->tail(flcn, queue, &q_tail, QUEUE_GET); + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, tail GET failed", + flcn->flcn_id, queue->id); + goto exit; + } + +exit: + /* release mutex */ + nvgpu_mutex_release(&queue->mutex); + + return q_head == q_tail; +} + +void nvgpu_flcn_queue_free(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + nvgpu_log(flcn->g, gpu_dbg_pmu, "flcn id-%d q-id %d: index %d ", + flcn->flcn_id, queue->id, queue->index); + + /* destroy mutex */ + nvgpu_mutex_destroy(&queue->mutex); + + /* clear data*/ + memset(queue, 0, sizeof(struct nvgpu_falcon_queue)); +} + +int nvgpu_flcn_queue_init(struct nvgpu_falcon *flcn, + struct nvgpu_falcon_queue *queue) +{ + struct gk20a *g = flcn->g; + int err = 0; + + nvgpu_log(g, gpu_dbg_pmu, + "flcn id-%d q-id %d: index %d, offset 0x%08x, size 0x%08x", + flcn->flcn_id, queue->id, queue->index, + queue->offset, queue->size); + + /* init mutex */ + err = nvgpu_mutex_init(&queue->mutex); + if (err != 0) { + goto exit; + } + + flcn_queue_init_dmem_queue(flcn, queue); + +exit: + if (err != 0) { + nvgpu_err(flcn->g, "flcn-%d queue-%d, init failed", + flcn->flcn_id, queue->id); + } + + return err; +} + diff --git a/drivers/gpu/nvgpu/common/pmu/pmu.c b/drivers/gpu/nvgpu/common/pmu/pmu.c index b9ac50be..327f67d3 100644 --- a/drivers/gpu/nvgpu/common/pmu/pmu.c +++ b/drivers/gpu/nvgpu/common/pmu/pmu.c @@ -517,8 +517,9 @@ int nvgpu_pmu_destroy(struct gk20a *g) pmu->isr_enabled = false; nvgpu_mutex_release(&pmu->isr_mutex); - for (i = 0; i < PMU_QUEUE_COUNT; i++) - nvgpu_mutex_destroy(&pmu->queue[i].mutex); + for (i = 0; i < PMU_QUEUE_COUNT; i++) { + nvgpu_flcn_queue_free(pmu->flcn, &pmu->queue[i]); + } nvgpu_pmu_state_change(g, PMU_STATE_OFF, false); pmu->pmu_ready = false; diff --git a/drivers/gpu/nvgpu/common/pmu/pmu_fw.c b/drivers/gpu/nvgpu/common/pmu/pmu_fw.c index 359c19ca..53eae49a 100644 --- a/drivers/gpu/nvgpu/common/pmu/pmu_fw.c +++ b/drivers/gpu/nvgpu/common/pmu/pmu_fw.c @@ -848,7 +848,8 @@ static void perfmon_cmd_init_set_mov_avg_v1(struct pmu_perfmon_cmd *pc, init->samples_in_moving_avg = value; } -static void get_pmu_init_msg_pmu_queue_params_v1(struct pmu_queue *queue, +static void get_pmu_init_msg_pmu_queue_params_v1( + struct nvgpu_falcon_queue *queue, u32 id, void *pmu_init_msg) { struct pmu_init_msg_pmu_v1 *init = @@ -859,7 +860,8 @@ static void get_pmu_init_msg_pmu_queue_params_v1(struct pmu_queue *queue, queue->size = init->queue_info[id].size; } -static void get_pmu_init_msg_pmu_queue_params_v4(struct pmu_queue *queue, +static void get_pmu_init_msg_pmu_queue_params_v4( + struct nvgpu_falcon_queue *queue, u32 id, void *pmu_init_msg) { struct pmu_init_msg_pmu_v4 *init = pmu_init_msg; @@ -885,7 +887,8 @@ static void get_pmu_init_msg_pmu_queue_params_v4(struct pmu_queue *queue, queue->offset = init->queue_offset + current_ptr; } -static void get_pmu_init_msg_pmu_queue_params_v5(struct pmu_queue *queue, +static void get_pmu_init_msg_pmu_queue_params_v5( + struct nvgpu_falcon_queue *queue, u32 id, void *pmu_init_msg) { struct pmu_init_msg_pmu_v5 *init = pmu_init_msg; @@ -911,7 +914,8 @@ static void get_pmu_init_msg_pmu_queue_params_v5(struct pmu_queue *queue, queue->offset = init->queue_offset + current_ptr; } -static void get_pmu_init_msg_pmu_queue_params_v3(struct pmu_queue *queue, +static void get_pmu_init_msg_pmu_queue_params_v3( + struct nvgpu_falcon_queue *queue, u32 id, void *pmu_init_msg) { struct pmu_init_msg_pmu_v3 *init = diff --git a/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c b/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c index a00c2a5e..f34e942d 100644 --- a/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c +++ b/drivers/gpu/nvgpu/common/pmu/pmu_ipc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "gk20a/gk20a.h" @@ -100,295 +101,56 @@ int nvgpu_pmu_mutex_release(struct nvgpu_pmu *pmu, u32 id, u32 *token) return g->ops.pmu.pmu_mutex_release(pmu, id, token); } -/* queue */ +/* PMU falcon queue init */ int nvgpu_pmu_queue_init(struct nvgpu_pmu *pmu, u32 id, union pmu_init_msg_pmu *init) { struct gk20a *g = gk20a_from_pmu(pmu); - struct pmu_queue *queue = &pmu->queue[id]; - int err; - - err = nvgpu_mutex_init(&queue->mutex); - if (err) - return err; - - queue->id = id; - g->ops.pmu_ver.get_pmu_init_msg_pmu_queue_params(queue, id, init); - queue->mutex_id = id; - - nvgpu_pmu_dbg(g, "queue %d: index %d, offset 0x%08x, size 0x%08x", - id, queue->index, queue->offset, queue->size); - - return 0; -} - -static int pmu_queue_head(struct nvgpu_pmu *pmu, struct pmu_queue *queue, - u32 *head, bool set) -{ - struct gk20a *g = gk20a_from_pmu(pmu); - - return g->ops.pmu.pmu_queue_head(pmu, queue, head, set); -} - -static int pmu_queue_tail(struct nvgpu_pmu *pmu, struct pmu_queue *queue, - u32 *tail, bool set) -{ - struct gk20a *g = gk20a_from_pmu(pmu); - - return g->ops.pmu.pmu_queue_tail(pmu, queue, tail, set); -} - -static inline void pmu_queue_read(struct nvgpu_pmu *pmu, - u32 offset, u8 *dst, u32 size) -{ - nvgpu_flcn_copy_from_dmem(pmu->flcn, offset, dst, size, 0); -} - -static inline void pmu_queue_write(struct nvgpu_pmu *pmu, - u32 offset, u8 *src, u32 size) -{ - nvgpu_flcn_copy_to_dmem(pmu->flcn, offset, src, size, 0); -} - - -static int pmu_queue_lock(struct nvgpu_pmu *pmu, - struct pmu_queue *queue) -{ - int err; - - if (PMU_IS_MESSAGE_QUEUE(queue->id)) - return 0; + struct nvgpu_falcon_queue *queue = NULL; + u32 oflag = 0; + int err = 0; - if (PMU_IS_SW_COMMAND_QUEUE(queue->id)) { - nvgpu_mutex_acquire(&queue->mutex); - return 0; + if (PMU_IS_COMMAND_QUEUE(id)) { + /* + * set OFLAG_WRITE for command queue + * i.e, push from nvgpu & + * pop form falcon ucode + */ + oflag = OFLAG_WRITE; + } else if (PMU_IS_MESSAGE_QUEUE(id)) { + /* + * set OFLAG_READ for message queue + * i.e, push from falcon ucode & + * pop form nvgpu + */ + oflag = OFLAG_READ; + } else { + nvgpu_err(g, "invalid queue-id %d", id); + err = -EINVAL; + goto exit; } - err = nvgpu_pmu_mutex_acquire(pmu, queue->mutex_id, &queue->mutex_lock); - return err; -} - -static int pmu_queue_unlock(struct nvgpu_pmu *pmu, - struct pmu_queue *queue) -{ - int err; - - if (PMU_IS_MESSAGE_QUEUE(queue->id)) - return 0; + /* init queue parameters */ + queue = &pmu->queue[id]; + queue->id = id; + queue->oflag = oflag; + g->ops.pmu_ver.get_pmu_init_msg_pmu_queue_params(queue, id, init); - if (PMU_IS_SW_COMMAND_QUEUE(queue->id)) { - nvgpu_mutex_release(&queue->mutex); - return 0; + err = nvgpu_flcn_queue_init(pmu->flcn, queue); + if (err != 0) { + nvgpu_err(g, "queue-%d init failed", queue->id); } - err = nvgpu_pmu_mutex_release(pmu, queue->mutex_id, &queue->mutex_lock); +exit: return err; } -/* called by pmu_read_message, no lock */ -bool nvgpu_pmu_queue_is_empty(struct nvgpu_pmu *pmu, - struct pmu_queue *queue) -{ - u32 head, tail; - - pmu_queue_head(pmu, queue, &head, QUEUE_GET); - if (queue->opened && queue->oflag == OFLAG_READ) - tail = queue->position; - else - pmu_queue_tail(pmu, queue, &tail, QUEUE_GET); - - return head == tail; -} - -static bool pmu_queue_has_room(struct nvgpu_pmu *pmu, - struct pmu_queue *queue, u32 size, bool *need_rewind) -{ - u32 head, tail; - bool rewind = false; - unsigned int free; - - size = ALIGN(size, QUEUE_ALIGNMENT); - - pmu_queue_head(pmu, queue, &head, QUEUE_GET); - pmu_queue_tail(pmu, queue, &tail, QUEUE_GET); - if (head >= tail) { - free = queue->offset + queue->size - head; - free -= PMU_CMD_HDR_SIZE; - - if (size > free) { - rewind = true; - head = queue->offset; - } - } - - if (head < tail) - free = tail - head - 1; - - if (need_rewind) - *need_rewind = rewind; - - return size <= free; -} - -static int pmu_queue_push(struct nvgpu_pmu *pmu, - struct pmu_queue *queue, void *data, u32 size) -{ - struct gk20a *g = pmu->g; - - nvgpu_log_fn(g, " "); - - if (!queue->opened && queue->oflag == OFLAG_WRITE) { - nvgpu_err(gk20a_from_pmu(pmu), "queue not opened for write"); - return -EINVAL; - } - - pmu_queue_write(pmu, queue->position, data, size); - queue->position += ALIGN(size, QUEUE_ALIGNMENT); - return 0; -} - -static int pmu_queue_pop(struct nvgpu_pmu *pmu, - struct pmu_queue *queue, void *data, u32 size, - u32 *bytes_read) -{ - u32 head, tail, used; - - *bytes_read = 0; - - if (!queue->opened && queue->oflag == OFLAG_READ) { - nvgpu_err(gk20a_from_pmu(pmu), "queue not opened for read"); - return -EINVAL; - } - - pmu_queue_head(pmu, queue, &head, QUEUE_GET); - tail = queue->position; - - if (head == tail) - return 0; - - if (head > tail) - used = head - tail; - else - used = queue->offset + queue->size - tail; - - if (size > used) { - nvgpu_warn(gk20a_from_pmu(pmu), - "queue size smaller than request read"); - size = used; - } - - pmu_queue_read(pmu, tail, data, size); - queue->position += ALIGN(size, QUEUE_ALIGNMENT); - *bytes_read = size; - return 0; -} - -static void pmu_queue_rewind(struct nvgpu_pmu *pmu, - struct pmu_queue *queue) -{ - struct gk20a *g = gk20a_from_pmu(pmu); - struct pmu_cmd cmd; - - nvgpu_log_fn(g, " "); - - if (!queue->opened) { - nvgpu_err(gk20a_from_pmu(pmu), "queue not opened"); - return; - } - - if (queue->oflag == OFLAG_WRITE) { - cmd.hdr.unit_id = PMU_UNIT_REWIND; - cmd.hdr.size = PMU_CMD_HDR_SIZE; - pmu_queue_push(pmu, queue, &cmd, cmd.hdr.size); - nvgpu_pmu_dbg(g, "queue %d rewinded", queue->id); - } - - queue->position = queue->offset; -} - -/* open for read and lock the queue */ -static int pmu_queue_open_read(struct nvgpu_pmu *pmu, - struct pmu_queue *queue) -{ - int err; - - err = pmu_queue_lock(pmu, queue); - if (err) - return err; - - if (queue->opened) - BUG(); - - pmu_queue_tail(pmu, queue, &queue->position, QUEUE_GET); - queue->oflag = OFLAG_READ; - queue->opened = true; - - return 0; -} - -/* open for write and lock the queue - * make sure there's enough free space for the write - * */ -static int pmu_queue_open_write(struct nvgpu_pmu *pmu, - struct pmu_queue *queue, u32 size) -{ - struct gk20a *g = gk20a_from_pmu(pmu); - bool rewind = false; - int err; - - err = pmu_queue_lock(pmu, queue); - if (err) - return err; - - if (queue->opened) - BUG(); - - if (!pmu_queue_has_room(pmu, queue, size, &rewind)) { - nvgpu_pmu_dbg(g, "queue full: queue-id %d: index %d", - queue->id, queue->index); - pmu_queue_unlock(pmu, queue); - return -EAGAIN; - } - - pmu_queue_head(pmu, queue, &queue->position, QUEUE_GET); - queue->oflag = OFLAG_WRITE; - queue->opened = true; - - if (rewind) - pmu_queue_rewind(pmu, queue); - - return 0; -} - -/* close and unlock the queue */ -static int pmu_queue_close(struct nvgpu_pmu *pmu, - struct pmu_queue *queue, bool commit) -{ - if (!queue->opened) - return 0; - - if (commit) { - if (queue->oflag == OFLAG_READ) - pmu_queue_tail(pmu, queue, - &queue->position, QUEUE_SET); - else - pmu_queue_head(pmu, queue, - &queue->position, QUEUE_SET); - } - - queue->opened = false; - - pmu_queue_unlock(pmu, queue); - - return 0; -} - static bool pmu_validate_cmd(struct nvgpu_pmu *pmu, struct pmu_cmd *cmd, struct pmu_msg *msg, struct pmu_payload *payload, u32 queue_id) { struct gk20a *g = gk20a_from_pmu(pmu); - struct pmu_queue *queue; + struct nvgpu_falcon_queue *queue; u32 in_size, out_size; if (!PMU_IS_SW_COMMAND_QUEUE(queue_id)) @@ -459,7 +221,7 @@ static int pmu_write_cmd(struct nvgpu_pmu *pmu, struct pmu_cmd *cmd, u32 queue_id, unsigned long timeout_ms) { struct gk20a *g = gk20a_from_pmu(pmu); - struct pmu_queue *queue; + struct nvgpu_falcon_queue *queue; struct nvgpu_timeout timeout; int err; @@ -469,22 +231,13 @@ static int pmu_write_cmd(struct nvgpu_pmu *pmu, struct pmu_cmd *cmd, nvgpu_timeout_init(g, &timeout, timeout_ms, NVGPU_TIMER_CPU_TIMER); do { - err = pmu_queue_open_write(pmu, queue, cmd->hdr.size); + err = nvgpu_flcn_queue_push(pmu->flcn, queue, cmd, cmd->hdr.size); if (err == -EAGAIN && !nvgpu_timeout_expired(&timeout)) nvgpu_usleep_range(1000, 2000); else break; } while (1); - if (err) - goto clean_up; - - pmu_queue_push(pmu, queue, cmd, cmd->hdr.size); - - - err = pmu_queue_close(pmu, queue, true); - -clean_up: if (err) nvgpu_err(g, "fail to write cmd to queue %d", queue_id); else @@ -840,8 +593,9 @@ 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 pmu_queue *queue, - struct pmu_msg *msg, int *status) +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, bytes_read; @@ -849,17 +603,11 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, struct pmu_queue *queue, *status = 0; - if (nvgpu_pmu_queue_is_empty(pmu, queue)) - return false; - - err = pmu_queue_open_read(pmu, queue); - if (err) { - nvgpu_err(g, "fail to open queue %d for read", queue->id); - *status = err; + if (nvgpu_flcn_queue_is_empty(pmu->flcn, queue)) { return false; } - err = pmu_queue_pop(pmu, queue, &msg->hdr, + err = nvgpu_flcn_queue_pop(pmu->flcn, queue, &msg->hdr, PMU_MSG_HDR_SIZE, &bytes_read); if (err || bytes_read != PMU_MSG_HDR_SIZE) { nvgpu_err(g, "fail to read msg from queue %d", queue->id); @@ -868,9 +616,14 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, struct pmu_queue *queue, } if (msg->hdr.unit_id == PMU_UNIT_REWIND) { - pmu_queue_rewind(pmu, queue); + err = nvgpu_flcn_queue_rewind(pmu->flcn, queue); + if (err != 0) { + nvgpu_err(g, "fail to rewind queue %d", queue->id); + *status = err | -EINVAL; + goto clean_up; + } /* read again after rewind */ - err = pmu_queue_pop(pmu, queue, &msg->hdr, + err = nvgpu_flcn_queue_pop(pmu->flcn, queue, &msg->hdr, PMU_MSG_HDR_SIZE, &bytes_read); if (err || bytes_read != PMU_MSG_HDR_SIZE) { nvgpu_err(g, @@ -889,7 +642,7 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, struct pmu_queue *queue, if (msg->hdr.size > PMU_MSG_HDR_SIZE) { read_size = msg->hdr.size - PMU_MSG_HDR_SIZE; - err = pmu_queue_pop(pmu, queue, &msg->msg, + err = nvgpu_flcn_queue_pop(pmu->flcn, queue, &msg->msg, read_size, &bytes_read); if (err || bytes_read != read_size) { nvgpu_err(g, @@ -899,19 +652,9 @@ static bool pmu_read_message(struct nvgpu_pmu *pmu, struct pmu_queue *queue, } } - err = pmu_queue_close(pmu, queue, true); - if (err) { - nvgpu_err(g, "fail to close queue %d", queue->id); - *status = err; - return false; - } - return true; clean_up: - err = pmu_queue_close(pmu, queue, false); - if (err) - nvgpu_err(g, "fail to close queue %d", queue->id); return false; } -- cgit v1.2.2