xref: /openbmc/hiomapd/mboxd.h (revision ef0c8360)
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 <linux/blktrace_api.h>
9 #include <mtd/mtd-abi.h>
10 #include <systemd/sd-bus.h>
11 #include <poll.h>
12 #include <stdbool.h>
13 
14 #include "backend.h"
15 #include "protocol.h"
16 #include "transport.h"
17 #include "vpnor/backend.h"
18 #include "windows.h"
19 
20 enum api_version {
21 	API_VERSION_INVAL	= 0,
22 	API_VERSION_1		= 1,
23 	API_VERSION_2		= 2
24 };
25 
26 #define API_MIN_VERSION			API_VERSION_1
27 #define API_MAX_VERSION			API_VERSION_2
28 
29 #define THIS_NAME			"Mailbox Daemon"
30 
31 /* Argument Flags */
32 #define FLAGS_NONE			0x00
33 #define FLAGS_SHORT_LIFETIME		0x01
34 
35 /* BMC Event Notification */
36 #define BMC_EVENT_PROTOCOL_RESET	0x01
37 #define BMC_EVENT_WINDOW_RESET		0x02
38 #define BMC_EVENT_ACK_MASK		(BMC_EVENT_PROTOCOL_RESET | \
39 					BMC_EVENT_WINDOW_RESET)
40 #define BMC_EVENT_FLASH_CTRL_LOST	0x40
41 #define BMC_EVENT_DAEMON_READY		0x80
42 #define BMC_EVENT_V1_MASK		BMC_EVENT_PROTOCOL_RESET
43 #define BMC_EVENT_V2_MASK		(BMC_EVENT_PROTOCOL_RESET | \
44 					BMC_EVENT_WINDOW_RESET | \
45 					BMC_EVENT_FLASH_CTRL_LOST | \
46 					BMC_EVENT_DAEMON_READY)
47 
48 /* 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
54 #define TOTAL_FDS		4
55 
56 #define MAPS_FLASH		(1 << 0)
57 #define MAPS_MEM		(1 << 1)
58 #define STATE_SUSPENDED		(1 << 7)
59 
60 enum 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
71 };
72 
73 struct mbox_context {
74 	enum api_version version;
75 	const struct protocol_ops *protocol;
76 	const struct transport_ops *transport;
77 	struct backend backend;
78 
79 	/* Commandline parameters */
80 	const char *source;
81 
82 /* System State */
83 	enum mbox_state state;
84 	struct pollfd fds[TOTAL_FDS];
85 	sd_bus *bus;
86 	bool terminate;
87 	uint8_t bmc_events;
88 	uint8_t prev_seq;
89 
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;
105 
106 	/* Tracing */
107 	int blktracefd;
108 	struct blk_io_trace trace;
109 	int64_t blktrace_start;
110 };
111 
112 #endif /* MBOX_H */
113