From 8ef1f2db87f8f23226569359f4f5d20cfb7bf7af Mon Sep 17 00:00:00 2001 From: Mahesh Kumar Date: Wed, 10 Aug 2022 14:09:58 +0530 Subject: [PATCH] platform: dce: FSM incremental fixes This patch addresses design review comments for FSM - Add comment to update design doc on FSM update - Create wrapper function to check bootcmd complete status - move bootstrapping functions to dce_bootstrap.c file - Fix sw resource init/deinit function name Bug 3583331 Signed-off-by: Mahesh Kumar Change-Id: I77f05135f7ec1882922907f8acef50def639d26d Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2758902 Reviewed-by: Santosh Galma Reviewed-by: svcacv Reviewed-by: svc_kernel_abi Reviewed-by: Arun Swain GVS: Gerrit_Virtual_Submit --- drivers/platform/tegra/dce/dce-admin.c | 6 +- drivers/platform/tegra/dce/dce-bootstrap.c | 70 ++++++++++++++++ drivers/platform/tegra/dce/dce-fsm.c | 7 ++ drivers/platform/tegra/dce/dce-init-deinit.c | 6 +- drivers/platform/tegra/dce/dce-worker.c | 80 ++----------------- .../platform/tegra/dce/include/dce-worker.h | 4 +- drivers/platform/tegra/dce/include/dce.h | 15 ++++ 7 files changed, 105 insertions(+), 83 deletions(-) diff --git a/drivers/platform/tegra/dce/dce-admin.c b/drivers/platform/tegra/dce/dce-admin.c index ffc0011a..10d97bd3 100644 --- a/drivers/platform/tegra/dce/dce-admin.c +++ b/drivers/platform/tegra/dce/dce-admin.c @@ -309,10 +309,10 @@ int dce_admin_handle_ipc_requested_event(struct tegra_dce *d, void *params) (struct dce_admin_send_msg_params *)params; /* - * Do not handle admin IPC if bootstrap is not completed + * Do not handle admin IPC if boot commands are not completed */ - if ((d->boot_status & DCE_FW_BOOTSTRAP_DONE) == 0) { - dce_err(d, "Bootstrap not yet completed\n"); + if (!dce_is_bootcmds_done(d)) { + dce_err(d, "Boot commands are not yet completed\n"); ret = -EINVAL; goto out; } diff --git a/drivers/platform/tegra/dce/dce-bootstrap.c b/drivers/platform/tegra/dce/dce-bootstrap.c index 04d513c7..31da8840 100644 --- a/drivers/platform/tegra/dce/dce-bootstrap.c +++ b/drivers/platform/tegra/dce/dce-bootstrap.c @@ -144,6 +144,76 @@ int dce_handle_boot_complete_received_event(struct tegra_dce *d, void *params) return 0; } +/* + * dce_start_boot_flow : Start dce bootstrap flow + * + * @d : Pointer to tegra_dce struct. + * + * Return : 0 if successful else error code + */ +static int +dce_start_boot_flow(struct tegra_dce *d) +{ + int ret = 0; + + ret = dce_start_bootstrap_flow(d); + if (ret) { + dce_err(d, "DCE_BOOT_FAILED: Bootstrap flow didn't complete"); + goto exit; + } + + dce_admin_ivc_channel_reset(d); + + ret = dce_start_admin_seq(d); + if (ret) { + dce_err(d, "DCE_BOOT_FAILED: Admin flow didn't complete"); + } else { + d->boot_status |= DCE_FW_BOOT_DONE; + dce_info(d, "DCE_BOOT_DONE"); + } + +exit: + if (ret) + d->boot_status |= DCE_STATUS_FAILED; + + return ret; +} + +/** + * dce_bootstrap_work_fn : execute fsm start and bootstrap flow + * + * @d : Pointer to tegra_dce struct. + * + * Return : void + */ +void dce_bootstrap_work_fn(struct tegra_dce *d) +{ + int ret = 0; + + if (d == NULL) { + dce_err(d, "tegra_dce struct is NULL"); + return; + } + + ret = dce_fsm_post_event(d, EVENT_ID_DCE_FSM_START, NULL); + if (ret) { + dce_err(d, "FSM start failed\n"); + return; + } + + ret = dce_fsm_post_event(d, EVENT_ID_DCE_BOOT_COMPLETE_REQUESTED, NULL); + if (ret) { + dce_err(d, "Error while posting DCE_BOOT_COMPLETE_REQUESTED event"); + return; + } + + ret = dce_start_boot_flow(d); + if (ret) { + dce_err(d, "DCE bootstrapping failed\n"); + return; + } +} + /** * dce_handle_irq_status - Handles irq status from DCE * diff --git a/drivers/platform/tegra/dce/dce-fsm.c b/drivers/platform/tegra/dce/dce-fsm.c index a18729ce..4430c8a5 100644 --- a/drivers/platform/tegra/dce/dce-fsm.c +++ b/drivers/platform/tegra/dce/dce-fsm.c @@ -19,6 +19,9 @@ struct dce_event_process_struct { int (*fsm_event_handle)(struct tegra_dce *d, void *params); }; +/* + * Please update FSM design Document, whenever updating below event table + */ static struct dce_event_process_struct event_process_table[] = { { .event = EVENT_ID_DCE_FSM_START, @@ -120,6 +123,8 @@ int dce_handle_event_stub(struct tegra_dce *d, void *params) * @event : Event for which FSM state need to be set * * Return : void + * + * Please update FSM design Document, whenever updating below event states */ static void dce_fsm_set_state(struct tegra_dce *d, @@ -211,6 +216,8 @@ dce_fsm_set_state(struct tegra_dce *d, * @event : Posted FSM event * * @return : ESUCCESS if event valid else error code + * + * Please update FSM design Document, whenever updating below event validation */ static int dce_fsm_validate_event(struct tegra_dce *d, diff --git a/drivers/platform/tegra/dce/dce-init-deinit.c b/drivers/platform/tegra/dce/dce-init-deinit.c index 4f405b96..626994df 100644 --- a/drivers/platform/tegra/dce/dce-init-deinit.c +++ b/drivers/platform/tegra/dce/dce-init-deinit.c @@ -44,7 +44,7 @@ int dce_driver_init(struct tegra_dce *d) goto err_client_init; } - ret = dce_sw_resource_init(d); + ret = dce_work_cond_sw_resource_init(d); if (ret) { dce_err(d, "dce sw resource init failed"); goto err_sw_init; @@ -61,7 +61,7 @@ int dce_driver_init(struct tegra_dce *d) return ret; err_fsm_init: - dce_sw_resource_deinit(d); + dce_work_cond_sw_resource_deinit(d); err_sw_init: dce_client_deinit(d); err_client_init: @@ -89,7 +89,7 @@ void dce_driver_deinit(struct tegra_dce *d) dce_fsm_deinit(d); - dce_sw_resource_deinit(d); + dce_work_cond_sw_resource_deinit(d); dce_client_deinit(d); diff --git a/drivers/platform/tegra/dce/dce-worker.c b/drivers/platform/tegra/dce/dce-worker.c index 1f3541da..6abb775f 100644 --- a/drivers/platform/tegra/dce/dce-worker.c +++ b/drivers/platform/tegra/dce/dce-worker.c @@ -72,84 +72,14 @@ void dce_wakeup_interruptible(struct tegra_dce *d, u32 msg_id) dce_cond_signal_interruptible(&wait->cond_wait); } -/* - * dce_start_boot_flow : Start dce bootstrap flow +/** + * dce_work_cond_sw_resource_init : Init dce workqueues related resources * * @d : Pointer to tegra_dce struct. * * Return : 0 if successful else error code */ -static int -dce_start_boot_flow(struct tegra_dce *d) -{ - int ret = 0; - - ret = dce_start_bootstrap_flow(d); - if (ret) { - dce_warn(d, "DCE_BOOT_FAILED: Bootstrap flow didn't complete"); - goto exit; - } - - dce_admin_ivc_channel_reset(d); - - ret = dce_start_admin_seq(d); - if (ret) { - dce_warn(d, "DCE_BOOT_FAILED: Admin flow didn't complete"); - } else { - d->boot_status |= DCE_FW_BOOT_DONE; - dce_info(d, "DCE_BOOT_DONE"); - } - -exit: - if (ret) - d->boot_status |= DCE_STATUS_FAILED; - - return ret; -} - -/** - * dce_bootstrap_work_fn : execute fsm start and bootstrap flow - * - * @d : Pointer to tegra_dce struct. - * - * Return : void - */ -void dce_bootstrap_work_fn(struct tegra_dce *d) -{ - int ret = 0; - - if (d == NULL) { - dce_err(d, "tegra_dce struct is NULL"); - return; - } - - ret = dce_fsm_post_event(d, EVENT_ID_DCE_FSM_START, NULL); - if (ret) { - dce_err(d, "FSM start failed\n"); - return; - } - - ret = dce_fsm_post_event(d, EVENT_ID_DCE_BOOT_COMPLETE_REQUESTED, NULL); - if (ret) { - dce_err(d, "Error while posting DCE_BOOT_COMPLETE_REQUESTED event"); - return; - } - - ret = dce_start_boot_flow(d); - if (ret) { - dce_err(d, "DCE bootstrapping failed\n"); - return; - } -} - -/** - * dce_sw_resource_init : Init dce workques related resources - * - * @d : Pointer to tegra_dce struct. - * - * Return : 0 if successful else error code - */ -int dce_sw_resource_init(struct tegra_dce *d) +int dce_work_cond_sw_resource_init(struct tegra_dce *d) { int ret = 0; int i; @@ -185,13 +115,13 @@ exit: } /** - * dce_sw_resource_deinit : de-init dce workques related resources + * dce_work_cond_sw_resource_deinit : de-init dce workqueues related resources * * @d : Pointer to tegra_dce struct. * * Return : void */ -void dce_sw_resource_deinit(struct tegra_dce *d) +void dce_work_cond_sw_resource_deinit(struct tegra_dce *d) { int i; diff --git a/drivers/platform/tegra/dce/include/dce-worker.h b/drivers/platform/tegra/dce/include/dce-worker.h index 2b00ea57..d8a2abe5 100644 --- a/drivers/platform/tegra/dce/include/dce-worker.h +++ b/drivers/platform/tegra/dce/include/dce-worker.h @@ -32,8 +32,8 @@ struct dce_wait_cond { struct dce_cond cond_wait; }; -int dce_sw_resource_init(struct tegra_dce *d); -void dce_sw_resource_deinit(struct tegra_dce *d); +int dce_work_cond_sw_resource_init(struct tegra_dce *d); +void dce_work_cond_sw_resource_deinit(struct tegra_dce *d); void dce_schedule_boot_complete_wait_worker(struct tegra_dce *d); int dce_wait_interruptible(struct tegra_dce *d, u32 msg_id); void dce_wakeup_interruptible(struct tegra_dce *d, u32 msg_id); diff --git a/drivers/platform/tegra/dce/include/dce.h b/drivers/platform/tegra/dce/include/dce.h index df21555f..f16291bc 100644 --- a/drivers/platform/tegra/dce/include/dce.h +++ b/drivers/platform/tegra/dce/include/dce.h @@ -290,6 +290,20 @@ static inline void dce_set_boot_complete(struct tegra_dce *d, bool val) d->boot_complete = val; } +/** + * dce_is_bootcmds_done - Checks if dce bootstrap bootcmds done. + * + * Chekc if all the mailbox boot commands are completed + * + * @d - Pointer to tegra_dce struct. + * + * Return : True if bootcmds are completed + */ +static inline bool dce_is_bootcmds_done(struct tegra_dce *d) +{ + return (d->boot_status & DCE_FW_BOOTSTRAP_DONE) ? true : false; +} + /** * dce_is_bootstrap_done - check if dce bootstrap is done. * @@ -358,6 +372,7 @@ const char *dce_get_fw_name(struct tegra_dce *d); int dce_driver_init(struct tegra_dce *d); void dce_driver_deinit(struct tegra_dce *d); +void dce_bootstrap_work_fn(struct tegra_dce *d); int dce_start_bootstrap_flow(struct tegra_dce *d); int dce_boot_interface_init(struct tegra_dce *d); void dce_boot_interface_deinit(struct tegra_dce *d);