xref: /openbmc/hiomapd/mboxd.h (revision 0297e5b8)
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright (C) 2018 IBM Corp. */
3 
4 #ifndef MBOX_H
5 #define MBOX_H
6 
7 #include <assert.h>
8 #include <mtd/mtd-abi.h>
9 #include <systemd/sd-bus.h>
10 #include <poll.h>
11 #include <stdbool.h>
12 
13 #include "backend.h"
14 #include "protocol.h"
15 #include "transport.h"
16 #include "vpnor/mboxd_pnor_partition_table.h"
17 #include "windows.h"
18 
19 enum api_version {
20 	API_VERSION_INVAL	= 0,
21 	API_VERSION_1		= 1,
22 	API_VERSION_2		= 2
23 };
24 
25 #define API_MIN_VERSION			API_VERSION_1
26 #define API_MAX_VERSION			API_VERSION_2
27 
28 #define THIS_NAME			"Mailbox Daemon"
29 
30 /* Argument Flags */
31 #define FLAGS_NONE			0x00
32 #define FLAGS_SHORT_LIFETIME		0x01
33 
34 /* BMC Event Notification */
35 #define BMC_EVENT_PROTOCOL_RESET	0x01
36 #define BMC_EVENT_WINDOW_RESET		0x02
37 #define BMC_EVENT_ACK_MASK		(BMC_EVENT_PROTOCOL_RESET | \
38 					BMC_EVENT_WINDOW_RESET)
39 #define BMC_EVENT_FLASH_CTRL_LOST	0x40
40 #define BMC_EVENT_DAEMON_READY		0x80
41 #define BMC_EVENT_V1_MASK		BMC_EVENT_PROTOCOL_RESET
42 #define BMC_EVENT_V2_MASK		(BMC_EVENT_PROTOCOL_RESET | \
43 					BMC_EVENT_WINDOW_RESET | \
44 					BMC_EVENT_FLASH_CTRL_LOST | \
45 					BMC_EVENT_DAEMON_READY)
46 
47 /* Put polled file descriptors first */
48 #define DBUS_FD			0
49 #define MBOX_FD			1
50 #define SIG_FD			2
51 #define POLL_FDS		3 /* Number of FDs we poll on */
52 #define LPC_CTRL_FD		3
53 #define TOTAL_FDS		4
54 
55 #define MAPS_FLASH		(1 << 0)
56 #define MAPS_MEM		(1 << 1)
57 #define STATE_SUSPENDED		(1 << 7)
58 
59 enum mbox_state {
60 	/* Still Initing */
61 	UNINITIALISED = 0,
62 	/* Active and LPC Maps Flash */
63 	ACTIVE_MAPS_FLASH = MAPS_FLASH,
64 	/* Suspended and LPC Maps Flash */
65 	SUSPEND_MAPS_FLASH = STATE_SUSPENDED | MAPS_FLASH,
66 	/* Active and LPC Maps Memory */
67 	ACTIVE_MAPS_MEM = MAPS_MEM,
68 	/* Suspended and LPC Maps Memory */
69 	SUSPEND_MAPS_MEM = STATE_SUSPENDED | MAPS_MEM
70 };
71 
72 struct mbox_context {
73 	enum api_version version;
74 	const struct protocol_ops *protocol;
75 	const struct transport_ops *transport;
76 	struct backend backend;
77 
78 	/* Commandline parameters */
79 	const char *path;
80 
81 /* System State */
82 	enum mbox_state state;
83 	struct pollfd fds[TOTAL_FDS];
84 	sd_bus *bus;
85 	bool terminate;
86 	uint8_t bmc_events;
87 	uint8_t prev_seq;
88 
89 /* Window State */
90 	/* The window list struct containing all current "windows" */
91 	struct window_list windows;
92 	/* The window the host is currently pointed at */
93 	struct window_context *current;
94 	/* Is the current window a write one */
95 	bool current_is_write;
96 
97 /* Memory & Flash State */
98 	/* Reserved Memory Region */
99 	void *mem;
100 	/* Reserved Mem Size (bytes) */
101 	uint32_t mem_size;
102 	/* LPC Bus Base Address (bytes) */
103 	uint32_t lpc_base;
104 };
105 
106 #endif /* MBOX_H */
107