blob: 6b14a242a8d7cce9d387d862d1cde6b65b61442b [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
Cyril Bur314929b2016-10-14 15:55:16 +11003
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11004#ifndef MBOX_H
5#define MBOX_H
Cyril Bur314929b2016-10-14 15:55:16 +11006
Evan Lojewskif1e547c2019-03-14 14:34:33 +10307#include <assert.h>
Stewart Smithef0c8362018-11-19 13:49:46 +11008#include <linux/blktrace_api.h>
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11009#include <mtd/mtd-abi.h>
10#include <systemd/sd-bus.h>
Andrew Jeffery8ecbdb52017-04-10 16:26:08 +093011#include <poll.h>
12#include <stdbool.h>
Andrew Jeffery1e531af2018-08-07 13:32:57 +093013
Evan Lojewskif1e547c2019-03-14 14:34:33 +103014#include "backend.h"
Andrew Jeffery1e531af2018-08-07 13:32:57 +093015#include "protocol.h"
Andrew Jeffery5335f092018-08-09 14:56:08 +093016#include "transport.h"
Andrew Jefferyf4bc3352019-03-18 12:09:48 +103017#include "vpnor/backend.h"
Andrew Jeffery26558db2018-08-10 00:22:38 +093018#include "windows.h"
Cyril Bur314929b2016-10-14 15:55:16 +110019
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110020enum api_version {
21 API_VERSION_INVAL = 0,
22 API_VERSION_1 = 1,
23 API_VERSION_2 = 2
Cyril Bur314929b2016-10-14 15:55:16 +110024};
25
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110026#define API_MIN_VERSION API_VERSION_1
27#define API_MAX_VERSION API_VERSION_2
28
29#define THIS_NAME "Mailbox Daemon"
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110030
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110031/* Argument Flags */
32#define FLAGS_NONE 0x00
33#define FLAGS_SHORT_LIFETIME 0x01
34
35/* BMC Event Notification */
Andrew Jefferyfab672b2018-11-01 17:12:09 +103036#define BMC_EVENT_PROTOCOL_RESET 0x01
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110037#define BMC_EVENT_WINDOW_RESET 0x02
Andrew Jefferyfab672b2018-11-01 17:12:09 +103038#define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110039 BMC_EVENT_WINDOW_RESET)
40#define BMC_EVENT_FLASH_CTRL_LOST 0x40
41#define BMC_EVENT_DAEMON_READY 0x80
Andrew Jefferyfab672b2018-11-01 17:12:09 +103042#define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET
43#define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110044 BMC_EVENT_WINDOW_RESET | \
45 BMC_EVENT_FLASH_CTRL_LOST | \
46 BMC_EVENT_DAEMON_READY)
47
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110048/* Put polled file descriptors first */
49#define DBUS_FD 0
50#define MBOX_FD 1
51#define SIG_FD 2
52#define POLL_FDS 3 /* Number of FDs we poll on */
53#define LPC_CTRL_FD 3
Evan Lojewskif1e547c2019-03-14 14:34:33 +103054#define TOTAL_FDS 4
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110055
56#define MAPS_FLASH (1 << 0)
57#define MAPS_MEM (1 << 1)
58#define STATE_SUSPENDED (1 << 7)
Andrew Jeffery26558db2018-08-10 00:22:38 +093059
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110060enum mbox_state {
61 /* Still Initing */
62 UNINITIALISED = 0,
63 /* Active and LPC Maps Flash */
64 ACTIVE_MAPS_FLASH = MAPS_FLASH,
65 /* Suspended and LPC Maps Flash */
66 SUSPEND_MAPS_FLASH = STATE_SUSPENDED | MAPS_FLASH,
67 /* Active and LPC Maps Memory */
68 ACTIVE_MAPS_MEM = MAPS_MEM,
69 /* Suspended and LPC Maps Memory */
70 SUSPEND_MAPS_MEM = STATE_SUSPENDED | MAPS_MEM
Cyril Bur314929b2016-10-14 15:55:16 +110071};
72
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110073struct mbox_context {
Andrew Jeffery1e531af2018-08-07 13:32:57 +093074 enum api_version version;
75 const struct protocol_ops *protocol;
Andrew Jeffery5335f092018-08-09 14:56:08 +093076 const struct transport_ops *transport;
Evan Lojewskif1e547c2019-03-14 14:34:33 +103077 struct backend backend;
78
79 /* Commandline parameters */
Andrew Jeffery5320f6e2019-03-15 12:40:41 +103080 const char *source;
Andrew Jeffery1e531af2018-08-07 13:32:57 +093081
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110082/* System State */
83 enum mbox_state state;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110084 struct pollfd fds[TOTAL_FDS];
85 sd_bus *bus;
86 bool terminate;
87 uint8_t bmc_events;
Andrew Jeffery55dede62017-04-24 16:13:06 +093088 uint8_t prev_seq;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110089
90/* Window State */
91 /* The window list struct containing all current "windows" */
92 struct window_list windows;
93 /* The window the host is currently pointed at */
94 struct window_context *current;
95 /* Is the current window a write one */
96 bool current_is_write;
97
98/* Memory & Flash State */
99 /* Reserved Memory Region */
100 void *mem;
101 /* Reserved Mem Size (bytes) */
102 uint32_t mem_size;
103 /* LPC Bus Base Address (bytes) */
104 uint32_t lpc_base;
Stewart Smithef0c8362018-11-19 13:49:46 +1100105
106 /* Tracing */
107 int blktracefd;
108 struct blk_io_trace trace;
109 int64_t blktrace_start;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +1100110};
111
112#endif /* MBOX_H */