From f69760da1a57638552042cdc12af58f12ecf34f3 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Thu, 14 Mar 2019 16:54:13 +1030 Subject: [PATCH] protocol: Introduce protocol_reset() protocol_reset() encapsulates the actions necessary to return the LPC state to what's required to boot the host. This is backend dependent; for the mtd backend we can simply point the bridge at the host flash AHB mapping, and for the virtual pnor we want to rearrange the content of the LPC reserved memory (leaving the bridge pointed there). In either case the state of the FWH address space is distured, so inform the host as necessary. Change-Id: Ie8efd1f703a3616c33f76f4e735c1efea039146c Signed-off-by: Andrew Jeffery --- control.c | 15 +-------------- mboxd.c | 31 +++++-------------------------- protocol.c | 35 +++++++++++++++++++++++++++++++++++ protocol.h | 6 ++++++ 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/control.c b/control.c index ceada6b..648e1c5 100644 --- a/control.c +++ b/control.c @@ -36,8 +36,6 @@ int control_lpc_state(struct mbox_context *context) int control_reset(struct mbox_context *context) { - int rc; - /* We don't let the host access flash if the daemon is suspened */ if (context->state & STATE_SUSPENDED) { return -EBUSY; @@ -49,18 +47,7 @@ int control_reset(struct mbox_context *context) * mapping back to flash, or memory in case we're using a virtual pnor. * Better set the bmc event to notify the host of this. */ - if (windows_reset_all(context)) { - rc = protocol_events_set(context, BMC_EVENT_WINDOW_RESET); - if (rc < 0) { - return rc; - } - } - rc = lpc_reset(context); - if (rc < 0) { - return rc; - } - - return 0; + return protocol_reset(context); } int control_kill(struct mbox_context *context) diff --git a/mboxd.c b/mboxd.c index 84bbf69..c2f2623 100644 --- a/mboxd.c +++ b/mboxd.c @@ -147,21 +147,9 @@ static int poll_loop(struct mbox_context *context) context->terminate = true; break; case SIGHUP: - /* Host didn't request reset -> Notify it */ - if (windows_reset_all(context)) { - rc = protocol_events_set(context, - BMC_EVENT_WINDOW_RESET); - if (rc < 0) { - MSG_ERR("Failed to notify host of reset, expect host-side corruption\n"); - break; - } - } - rc = lpc_reset(context); + rc = protocol_reset(context); if (rc < 0) { - MSG_ERR("WARNING: Failed to point the " - "LPC bus back to flash on " - "SIGHUP\nIf the host requires " - "this expect problems...\n"); + MSG_ERR("Failed to reset on SIGHUP\n"); } break; default: @@ -191,15 +179,9 @@ static int poll_loop(struct mbox_context *context) } } - /* Best to reset windows and the lpc mapping for safety */ - /* Host didn't request reset -> Notify it */ - windows_reset_all(context); - - rc = lpc_reset(context); - /* Not much we can do if this fails */ + rc = protocol_reset(context); if (rc < 0) { - MSG_ERR("WARNING: Failed to point the LPC bus back to flash\n" - "If the host requires this expect problems...\n"); + MSG_ERR("Failed to reset during poll loop cleanup\n"); } return rc; @@ -407,10 +389,7 @@ int main(int argc, char **argv) #endif /* Set the LPC bus mapping */ - rc = lpc_reset(context); - if (rc) { - MSG_ERR("LPC configuration failed, RESET required: %d\n", rc); - } + __protocol_reset(context); /* We're ready to go, alert the host */ context->bmc_events |= BMC_EVENT_DAEMON_READY; diff --git a/protocol.c b/protocol.c index 8eb06ae..2a04d89 100644 --- a/protocol.c +++ b/protocol.c @@ -532,3 +532,38 @@ void protocol_free(struct mbox_context *context) { return; } + +/* Don't do any state manipulation, just perform the reset */ +int __protocol_reset(struct mbox_context *context) +{ + windows_reset_all(context); + + return lpc_reset(context); +} + +/* Prevent the host from performing actions whilst reset takes place */ +int protocol_reset(struct mbox_context *context) +{ + int rc; + + rc = protocol_events_clear(context, BMC_EVENT_DAEMON_READY); + if (rc < 0) { + MSG_ERR("Failed to clear daemon ready state, reset failed\n"); + return rc; + } + + rc = __protocol_reset(context); + if (rc < 0) { + MSG_ERR("Failed to reset protocol, daemon remains not ready\n"); + return rc; + } + + rc = protocol_events_set(context, + BMC_EVENT_DAEMON_READY | BMC_EVENT_PROTOCOL_RESET); + if (rc < 0) { + MSG_ERR("Failed to set daemon ready state, daemon remains not ready\n"); + return rc; + } + + return 0; +} diff --git a/protocol.h b/protocol.h index 2c1e725..5a678c6 100644 --- a/protocol.h +++ b/protocol.h @@ -121,6 +121,12 @@ void protocol_free(struct mbox_context *context); int protocol_negotiate_version(struct mbox_context *context, uint8_t requested); +/* Sneaky reset: Don't tell the host */ +int __protocol_reset(struct mbox_context *context); + +/* Noisy reset: Tell the host */ +int protocol_reset(struct mbox_context *context); + int protocol_events_put(struct mbox_context *context, const struct transport_ops *ops); int protocol_events_set(struct mbox_context *context, uint8_t bmc_event); -- 2.30.2