Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | /* Copyright (C) 2018 IBM Corp. */ |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 3 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 4 | #ifndef MBOX_H |
| 5 | #define MBOX_H |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 6 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 7 | #include <assert.h> |
Stewart Smith | ef0c836 | 2018-11-19 13:49:46 +1100 | [diff] [blame] | 8 | #include <linux/blktrace_api.h> |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 9 | #include <mtd/mtd-abi.h> |
| 10 | #include <systemd/sd-bus.h> |
Andrew Jeffery | 8ecbdb5 | 2017-04-10 16:26:08 +0930 | [diff] [blame] | 11 | #include <poll.h> |
| 12 | #include <stdbool.h> |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 13 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 14 | #include "backend.h" |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 15 | #include "protocol.h" |
Andrew Jeffery | 5335f09 | 2018-08-09 14:56:08 +0930 | [diff] [blame] | 16 | #include "transport.h" |
Andrew Jeffery | f4bc335 | 2019-03-18 12:09:48 +1030 | [diff] [blame] | 17 | #include "vpnor/backend.h" |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 18 | #include "windows.h" |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 19 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 20 | enum api_version { |
| 21 | API_VERSION_INVAL = 0, |
| 22 | API_VERSION_1 = 1, |
| 23 | API_VERSION_2 = 2 |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 24 | }; |
| 25 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 26 | #define API_MIN_VERSION API_VERSION_1 |
| 27 | #define API_MAX_VERSION API_VERSION_2 |
| 28 | |
| 29 | #define THIS_NAME "Mailbox Daemon" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 30 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 31 | /* Argument Flags */ |
| 32 | #define FLAGS_NONE 0x00 |
| 33 | #define FLAGS_SHORT_LIFETIME 0x01 |
| 34 | |
| 35 | /* BMC Event Notification */ |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 36 | #define BMC_EVENT_PROTOCOL_RESET 0x01 |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 37 | #define BMC_EVENT_WINDOW_RESET 0x02 |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 38 | #define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 39 | BMC_EVENT_WINDOW_RESET) |
| 40 | #define BMC_EVENT_FLASH_CTRL_LOST 0x40 |
| 41 | #define BMC_EVENT_DAEMON_READY 0x80 |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 42 | #define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET |
| 43 | #define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 44 | BMC_EVENT_WINDOW_RESET | \ |
| 45 | BMC_EVENT_FLASH_CTRL_LOST | \ |
| 46 | BMC_EVENT_DAEMON_READY) |
| 47 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 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 |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 54 | #define TOTAL_FDS 4 |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 55 | |
| 56 | #define MAPS_FLASH (1 << 0) |
| 57 | #define MAPS_MEM (1 << 1) |
| 58 | #define STATE_SUSPENDED (1 << 7) |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 59 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 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 |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 71 | }; |
| 72 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 73 | struct mbox_context { |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 74 | enum api_version version; |
| 75 | const struct protocol_ops *protocol; |
Andrew Jeffery | 5335f09 | 2018-08-09 14:56:08 +0930 | [diff] [blame] | 76 | const struct transport_ops *transport; |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 77 | struct backend backend; |
| 78 | |
| 79 | /* Commandline parameters */ |
Andrew Jeffery | 5320f6e | 2019-03-15 12:40:41 +1030 | [diff] [blame] | 80 | const char *source; |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 81 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 82 | /* System State */ |
| 83 | enum mbox_state state; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 84 | struct pollfd fds[TOTAL_FDS]; |
| 85 | sd_bus *bus; |
| 86 | bool terminate; |
| 87 | uint8_t bmc_events; |
Andrew Jeffery | 55dede6 | 2017-04-24 16:13:06 +0930 | [diff] [blame] | 88 | uint8_t prev_seq; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 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; |
Stewart Smith | ef0c836 | 2018-11-19 13:49:46 +1100 | [diff] [blame] | 105 | |
| 106 | /* Tracing */ |
| 107 | int blktracefd; |
| 108 | struct blk_io_trace trace; |
| 109 | int64_t blktrace_start; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | #endif /* MBOX_H */ |