blob: 648e1c59bd5514ca62f2b6e9fa589d1b9c9ca92c [file] [log] [blame]
Andrew Jeffery68023072018-08-06 10:08:11 +09301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <errno.h>
4#include <stdlib.h>
5
Andrew Jeffery26558db2018-08-10 00:22:38 +09306#include "common.h"
Andrew Jeffery68023072018-08-06 10:08:11 +09307#include "dbus.h"
Andrew Jeffery26558db2018-08-10 00:22:38 +09308#include "mboxd.h"
Andrew Jefferyeebc6bd2018-08-08 10:38:19 +09309#include "flash.h"
Andrew Jefferycd186112018-08-08 10:47:55 +093010#include "lpc.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +093011#include "transport_mbox.h"
Andrew Jefferyf593b1b2018-08-08 11:01:04 +093012#include "windows.h"
Andrew Jeffery68023072018-08-06 10:08:11 +093013
14int control_ping(struct mbox_context *context)
15{
16 return 0;
17}
18
19int control_daemon_state(struct mbox_context *context)
20{
21 return (context->state & STATE_SUSPENDED) ?
22 DAEMON_STATE_SUSPENDED : DAEMON_STATE_ACTIVE;
23}
24
25int control_lpc_state(struct mbox_context *context)
26{
27 if ((context->state & MAPS_MEM) && !(context->state & MAPS_FLASH)) {
28 return LPC_STATE_MEM;
29 } else if (!(context->state & MAPS_MEM) &&
30 (context->state & MAPS_FLASH)) {
31 return LPC_STATE_FLASH;
32 }
33
34 return LPC_STATE_INVALID;
35}
36
37int control_reset(struct mbox_context *context)
38{
Andrew Jeffery68023072018-08-06 10:08:11 +093039 /* We don't let the host access flash if the daemon is suspened */
40 if (context->state & STATE_SUSPENDED) {
41 return -EBUSY;
42 }
43
Andrew Jefferycda29642018-08-30 12:01:40 +093044 /* FIXME: Comment below is wrong: windows_reset_all() does not flush! */
Andrew Jeffery68023072018-08-06 10:08:11 +093045 /*
46 * This will close (and flush) the current window and reset the lpc bus
47 * mapping back to flash, or memory in case we're using a virtual pnor.
48 * Better set the bmc event to notify the host of this.
49 */
Andrew Jefferyf69760d2019-03-14 16:54:13 +103050 return protocol_reset(context);
Andrew Jeffery68023072018-08-06 10:08:11 +093051}
52
53int control_kill(struct mbox_context *context)
54{
55 context->terminate = 1;
56
57 MSG_INFO("DBUS Kill - Exiting...\n");
58
59 return 0;
60}
61
62int control_modified(struct mbox_context *context)
63{
64 /* Flash has been modified - can no longer trust our erased bytemap */
Andrew Jefferyf953f792018-08-08 16:56:03 +093065 flash_set_bytemap(context, 0, context->flash_size, FLASH_DIRTY);
Andrew Jeffery68023072018-08-06 10:08:11 +093066
67 /* Force daemon to reload all windows -> Set BMC event to notify host */
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093068 if (windows_reset_all(context)) {
69 protocol_events_set(context, BMC_EVENT_WINDOW_RESET);
70 }
Andrew Jeffery68023072018-08-06 10:08:11 +093071
72 return 0;
73}
74
75int control_suspend(struct mbox_context *context)
76{
77 int rc;
78
79 if (context->state & STATE_SUSPENDED) {
80 /* Already Suspended */
Andrew Jefferyef9e62d2018-08-08 15:48:27 +093081 return 0;
Andrew Jeffery68023072018-08-06 10:08:11 +093082 }
83
84 /* Nothing to check - Just set the bit to notify the host */
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093085 rc = protocol_events_set(context, BMC_EVENT_FLASH_CTRL_LOST);
Andrew Jeffery68023072018-08-06 10:08:11 +093086 if (rc < 0) {
87 return rc;
88 }
89
90 context->state |= STATE_SUSPENDED;
91
92 return rc;
93}
94
95int control_resume(struct mbox_context *context, bool modified)
96{
97 int rc;
98
99 if (!(context->state & STATE_SUSPENDED)) {
100 /* We weren't suspended... */
Andrew Jefferyef9e62d2018-08-08 15:48:27 +0930101 return 0;
Andrew Jeffery68023072018-08-06 10:08:11 +0930102 }
103
104 if (modified) {
105 /* Call the flash modified handler */
106 control_modified(context);
107 }
108
109 /* Clear the bit and send the BMC Event to the host */
Andrew Jeffery2ebfd202018-08-20 11:46:28 +0930110 rc = protocol_events_clear(context, BMC_EVENT_FLASH_CTRL_LOST);
Andrew Jeffery68023072018-08-06 10:08:11 +0930111 if (rc < 0) {
Andrew Jefferyef9e62d2018-08-08 15:48:27 +0930112 return rc;
Andrew Jeffery68023072018-08-06 10:08:11 +0930113 }
114 context->state &= ~STATE_SUSPENDED;
115
116 return rc;
117}