blob: 1047e461d03434d3a95d7f5651951ecae6044571 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
Cyril Bur314929b2016-10-14 15:55:16 +11003
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11004#ifndef MBOX_H
5#define MBOX_H
Cyril Bur314929b2016-10-14 15:55:16 +11006
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11007#include <mtd/mtd-abi.h>
8#include <systemd/sd-bus.h>
Andrew Jeffery8ecbdb52017-04-10 16:26:08 +09309#include <poll.h>
10#include <stdbool.h>
Andrew Jeffery1e531af2018-08-07 13:32:57 +093011
12#include "protocol.h"
Andrew Jeffery5335f092018-08-09 14:56:08 +093013#include "transport.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103014#include "vpnor/mboxd_pnor_partition_table.h"
Andrew Jeffery26558db2018-08-10 00:22:38 +093015#include "windows.h"
Cyril Bur314929b2016-10-14 15:55:16 +110016
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110017enum api_version {
18 API_VERSION_INVAL = 0,
19 API_VERSION_1 = 1,
20 API_VERSION_2 = 2
Cyril Bur314929b2016-10-14 15:55:16 +110021};
22
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110023#define API_MIN_VERSION API_VERSION_1
24#define API_MAX_VERSION API_VERSION_2
25
26#define THIS_NAME "Mailbox Daemon"
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110027
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110028/* Argument Flags */
29#define FLAGS_NONE 0x00
30#define FLAGS_SHORT_LIFETIME 0x01
31
32/* BMC Event Notification */
Andrew Jefferyfab672b2018-11-01 17:12:09 +103033#define BMC_EVENT_PROTOCOL_RESET 0x01
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110034#define BMC_EVENT_WINDOW_RESET 0x02
Andrew Jefferyfab672b2018-11-01 17:12:09 +103035#define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110036 BMC_EVENT_WINDOW_RESET)
37#define BMC_EVENT_FLASH_CTRL_LOST 0x40
38#define BMC_EVENT_DAEMON_READY 0x80
Andrew Jefferyfab672b2018-11-01 17:12:09 +103039#define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET
40#define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110041 BMC_EVENT_WINDOW_RESET | \
42 BMC_EVENT_FLASH_CTRL_LOST | \
43 BMC_EVENT_DAEMON_READY)
44
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110045/* 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 Jeffery26558db2018-08-10 00:22:38 +093057
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110058enum 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 Bur314929b2016-10-14 15:55:16 +110069};
70
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110071struct mbox_context {
Andrew Jeffery1e531af2018-08-07 13:32:57 +093072 enum api_version version;
73 const struct protocol_ops *protocol;
Andrew Jeffery5335f092018-08-09 14:56:08 +093074 const struct transport_ops *transport;
Andrew Jeffery1e531af2018-08-07 13:32:57 +093075
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110076/* System State */
77 enum mbox_state state;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110078 struct pollfd fds[TOTAL_FDS];
79 sd_bus *bus;
80 bool terminate;
81 uint8_t bmc_events;
Andrew Jeffery55dede62017-04-24 16:13:06 +093082 uint8_t prev_seq;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110083
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 Kodihallib6a446f2017-04-29 13:01:49 -0500109#ifdef VIRTUAL_PNOR_ENABLED
110 /* Virtual PNOR partition table */
111 struct vpnor_partition_table *vpnor;
Ratan Gupta8441a392017-05-05 21:42:53 +0530112 struct vpnor_partition_paths paths;
Deepak Kodihallib6a446f2017-04-29 13:01:49 -0500113#endif
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +1100114};
115
116#endif /* MBOX_H */