blob: eff4f7e23e6282d8280ade9ce290001ad08d5d96 [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
6#include "dbus.h"
7#include "mbox.h"
Andrew Jefferyeebc6bd2018-08-08 10:38:19 +09308#include "flash.h"
Andrew Jefferycd186112018-08-08 10:47:55 +09309#include "lpc.h"
Andrew Jeffery68023072018-08-06 10:08:11 +093010#include "mboxd_msg.h"
Andrew Jefferyf593b1b2018-08-08 11:01:04 +093011#include "windows.h"
Andrew Jeffery68023072018-08-06 10:08:11 +093012
13int control_ping(struct mbox_context *context)
14{
15 return 0;
16}
17
18int control_daemon_state(struct mbox_context *context)
19{
20 return (context->state & STATE_SUSPENDED) ?
21 DAEMON_STATE_SUSPENDED : DAEMON_STATE_ACTIVE;
22}
23
24int control_lpc_state(struct mbox_context *context)
25{
26 if ((context->state & MAPS_MEM) && !(context->state & MAPS_FLASH)) {
27 return LPC_STATE_MEM;
28 } else if (!(context->state & MAPS_MEM) &&
29 (context->state & MAPS_FLASH)) {
30 return LPC_STATE_FLASH;
31 }
32
33 return LPC_STATE_INVALID;
34}
35
36int control_reset(struct mbox_context *context)
37{
38 int rc;
39
40 /* We don't let the host access flash if the daemon is suspened */
41 if (context->state & STATE_SUSPENDED) {
42 return -EBUSY;
43 }
44
45 /*
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 */
50 reset_all_windows(context, SET_BMC_EVENT);
Andrew Jeffery17971e42018-08-08 16:36:10 +093051 rc = lpc_reset(context);
Andrew Jeffery68023072018-08-06 10:08:11 +093052 if (rc < 0) {
53 return rc;
54 }
55
56 return 0;
57}
58
59int control_kill(struct mbox_context *context)
60{
61 context->terminate = 1;
62
63 MSG_INFO("DBUS Kill - Exiting...\n");
64
65 return 0;
66}
67
68int control_modified(struct mbox_context *context)
69{
70 /* Flash has been modified - can no longer trust our erased bytemap */
Andrew Jefferyf953f792018-08-08 16:56:03 +093071 flash_set_bytemap(context, 0, context->flash_size, FLASH_DIRTY);
Andrew Jeffery68023072018-08-06 10:08:11 +093072
73 /* Force daemon to reload all windows -> Set BMC event to notify host */
74 reset_all_windows(context, SET_BMC_EVENT);
75
76 return 0;
77}
78
79int control_suspend(struct mbox_context *context)
80{
81 int rc;
82
83 if (context->state & STATE_SUSPENDED) {
84 /* Already Suspended */
Andrew Jefferyef9e62d2018-08-08 15:48:27 +093085 return 0;
Andrew Jeffery68023072018-08-06 10:08:11 +093086 }
87
88 /* Nothing to check - Just set the bit to notify the host */
89 rc = set_bmc_events(context, BMC_EVENT_FLASH_CTRL_LOST, SET_BMC_EVENT);
90 if (rc < 0) {
91 return rc;
92 }
93
94 context->state |= STATE_SUSPENDED;
95
96 return rc;
97}
98
99int control_resume(struct mbox_context *context, bool modified)
100{
101 int rc;
102
103 if (!(context->state & STATE_SUSPENDED)) {
104 /* We weren't suspended... */
Andrew Jefferyef9e62d2018-08-08 15:48:27 +0930105 return 0;
Andrew Jeffery68023072018-08-06 10:08:11 +0930106 }
107
108 if (modified) {
109 /* Call the flash modified handler */
110 control_modified(context);
111 }
112
113 /* Clear the bit and send the BMC Event to the host */
114 rc = clr_bmc_events(context, BMC_EVENT_FLASH_CTRL_LOST, SET_BMC_EVENT);
Andrew Jeffery68023072018-08-06 10:08:11 +0930115 if (rc < 0) {
Andrew Jefferyef9e62d2018-08-08 15:48:27 +0930116 return rc;
Andrew Jeffery68023072018-08-06 10:08:11 +0930117 }
118 context->state &= ~STATE_SUSPENDED;
119
120 return rc;
121}