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 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 7 | #include <mtd/mtd-abi.h> |
| 8 | #include <systemd/sd-bus.h> |
Andrew Jeffery | 8ecbdb5 | 2017-04-10 16:26:08 +0930 | [diff] [blame] | 9 | #include <poll.h> |
| 10 | #include <stdbool.h> |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 11 | |
| 12 | #include "protocol.h" |
Andrew Jeffery | 5335f09 | 2018-08-09 14:56:08 +0930 | [diff] [blame] | 13 | #include "transport.h" |
Andrew Jeffery | 53c21aa | 2018-03-26 11:56:16 +1030 | [diff] [blame] | 14 | #include "vpnor/mboxd_pnor_partition_table.h" |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 15 | #include "windows.h" |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 16 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 17 | enum api_version { |
| 18 | API_VERSION_INVAL = 0, |
| 19 | API_VERSION_1 = 1, |
| 20 | API_VERSION_2 = 2 |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 21 | }; |
| 22 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 23 | #define API_MIN_VERSION API_VERSION_1 |
| 24 | #define API_MAX_VERSION API_VERSION_2 |
| 25 | |
| 26 | #define THIS_NAME "Mailbox Daemon" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 27 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 28 | /* Argument Flags */ |
| 29 | #define FLAGS_NONE 0x00 |
| 30 | #define FLAGS_SHORT_LIFETIME 0x01 |
| 31 | |
| 32 | /* BMC Event Notification */ |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 33 | #define BMC_EVENT_PROTOCOL_RESET 0x01 |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 34 | #define BMC_EVENT_WINDOW_RESET 0x02 |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 35 | #define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 36 | BMC_EVENT_WINDOW_RESET) |
| 37 | #define BMC_EVENT_FLASH_CTRL_LOST 0x40 |
| 38 | #define BMC_EVENT_DAEMON_READY 0x80 |
Andrew Jeffery | fab672b | 2018-11-01 17:12:09 +1030 | [diff] [blame] | 39 | #define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET |
| 40 | #define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 41 | BMC_EVENT_WINDOW_RESET | \ |
| 42 | BMC_EVENT_FLASH_CTRL_LOST | \ |
| 43 | BMC_EVENT_DAEMON_READY) |
| 44 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 45 | /* Put polled file descriptors first */ |
| 46 | #define DBUS_FD 0 |
| 47 | #define MBOX_FD 1 |
| 48 | #define SIG_FD 2 |
| 49 | #define POLL_FDS 3 /* Number of FDs we poll on */ |
| 50 | #define LPC_CTRL_FD 3 |
| 51 | #define MTD_FD 4 |
| 52 | #define TOTAL_FDS 5 |
| 53 | |
| 54 | #define MAPS_FLASH (1 << 0) |
| 55 | #define MAPS_MEM (1 << 1) |
| 56 | #define STATE_SUSPENDED (1 << 7) |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 57 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 58 | enum mbox_state { |
| 59 | /* Still Initing */ |
| 60 | UNINITIALISED = 0, |
| 61 | /* Active and LPC Maps Flash */ |
| 62 | ACTIVE_MAPS_FLASH = MAPS_FLASH, |
| 63 | /* Suspended and LPC Maps Flash */ |
| 64 | SUSPEND_MAPS_FLASH = STATE_SUSPENDED | MAPS_FLASH, |
| 65 | /* Active and LPC Maps Memory */ |
| 66 | ACTIVE_MAPS_MEM = MAPS_MEM, |
| 67 | /* Suspended and LPC Maps Memory */ |
| 68 | SUSPEND_MAPS_MEM = STATE_SUSPENDED | MAPS_MEM |
Cyril Bur | 314929b | 2016-10-14 15:55:16 +1100 | [diff] [blame] | 69 | }; |
| 70 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 71 | struct mbox_context { |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 72 | enum api_version version; |
| 73 | const struct protocol_ops *protocol; |
Andrew Jeffery | 5335f09 | 2018-08-09 14:56:08 +0930 | [diff] [blame] | 74 | const struct transport_ops *transport; |
Andrew Jeffery | 1e531af | 2018-08-07 13:32:57 +0930 | [diff] [blame] | 75 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 76 | /* System State */ |
| 77 | enum mbox_state state; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 78 | struct pollfd fds[TOTAL_FDS]; |
| 79 | sd_bus *bus; |
| 80 | bool terminate; |
| 81 | uint8_t bmc_events; |
Andrew Jeffery | 55dede6 | 2017-04-24 16:13:06 +0930 | [diff] [blame] | 82 | uint8_t prev_seq; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 83 | |
| 84 | /* Window State */ |
| 85 | /* The window list struct containing all current "windows" */ |
| 86 | struct window_list windows; |
| 87 | /* The window the host is currently pointed at */ |
| 88 | struct window_context *current; |
| 89 | /* Is the current window a write one */ |
| 90 | bool current_is_write; |
| 91 | |
| 92 | /* Memory & Flash State */ |
| 93 | /* Reserved Memory Region */ |
| 94 | void *mem; |
| 95 | /* Reserved Mem Size (bytes) */ |
| 96 | uint32_t mem_size; |
| 97 | /* LPC Bus Base Address (bytes) */ |
| 98 | uint32_t lpc_base; |
| 99 | /* Flash size from command line (bytes) */ |
| 100 | uint32_t flash_size; |
| 101 | /* Bytemap of the erased state of the entire flash */ |
| 102 | uint8_t *flash_bmap; |
| 103 | /* Erase size (as a shift) */ |
| 104 | uint32_t erase_size_shift; |
| 105 | /* Block size (as a shift) */ |
| 106 | uint32_t block_size_shift; |
| 107 | /* Actual Flash Info */ |
| 108 | struct mtd_info_user mtd_info; |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 109 | #ifdef VIRTUAL_PNOR_ENABLED |
| 110 | /* Virtual PNOR partition table */ |
| 111 | struct vpnor_partition_table *vpnor; |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 112 | struct vpnor_partition_paths paths; |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 113 | #endif |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | #endif /* MBOX_H */ |