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 <mtd/mtd-abi.h> 8 #include <systemd/sd-bus.h> 9 #include <poll.h> 10 #include <stdbool.h> 11 12 #include "protocol.h" 13 #include "transport.h" 14 #include "vpnor/mboxd_pnor_partition_table.h" 15 #include "windows.h" 16 17 enum api_version { 18 API_VERSION_INVAL = 0, 19 API_VERSION_1 = 1, 20 API_VERSION_2 = 2 21 }; 22 23 #define API_MIN_VERSION API_VERSION_1 24 #define API_MAX_VERSION API_VERSION_2 25 26 #define THIS_NAME "Mailbox Daemon" 27 28 /* Argument Flags */ 29 #define FLAGS_NONE 0x00 30 #define FLAGS_SHORT_LIFETIME 0x01 31 32 /* BMC Event Notification */ 33 #define BMC_EVENT_PROTOCOL_RESET 0x01 34 #define BMC_EVENT_WINDOW_RESET 0x02 35 #define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \ 36 BMC_EVENT_WINDOW_RESET) 37 #define BMC_EVENT_FLASH_CTRL_LOST 0x40 38 #define BMC_EVENT_DAEMON_READY 0x80 39 #define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET 40 #define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \ 41 BMC_EVENT_WINDOW_RESET | \ 42 BMC_EVENT_FLASH_CTRL_LOST | \ 43 BMC_EVENT_DAEMON_READY) 44 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) 57 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 69 }; 70 71 struct mbox_context { 72 enum api_version version; 73 const struct protocol_ops *protocol; 74 const struct transport_ops *transport; 75 76 /* System State */ 77 enum mbox_state state; 78 struct pollfd fds[TOTAL_FDS]; 79 sd_bus *bus; 80 bool terminate; 81 uint8_t bmc_events; 82 uint8_t prev_seq; 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; 109 #ifdef VIRTUAL_PNOR_ENABLED 110 /* Virtual PNOR partition table */ 111 struct vpnor_partition_table *vpnor; 112 struct vpnor_partition_paths paths; 113 #endif 114 }; 115 116 #endif /* MBOX_H */ 117