blob: 7930242b67b60c0c9365d5d7da22e7e87cf2f4ae [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
Evan Lojewskif1e547c2019-03-14 14:34:33 +10307#include <assert.h>
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11008#include <mtd/mtd-abi.h>
9#include <systemd/sd-bus.h>
Andrew Jeffery8ecbdb52017-04-10 16:26:08 +093010#include <poll.h>
11#include <stdbool.h>
Andrew Jeffery1e531af2018-08-07 13:32:57 +093012
Evan Lojewskif1e547c2019-03-14 14:34:33 +103013#include "backend.h"
Andrew Jeffery1e531af2018-08-07 13:32:57 +093014#include "protocol.h"
Andrew Jeffery5335f092018-08-09 14:56:08 +093015#include "transport.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103016#include "vpnor/mboxd_pnor_partition_table.h"
Andrew Jeffery26558db2018-08-10 00:22:38 +093017#include "windows.h"
Cyril Bur314929b2016-10-14 15:55:16 +110018
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110019enum api_version {
20 API_VERSION_INVAL = 0,
21 API_VERSION_1 = 1,
22 API_VERSION_2 = 2
Cyril Bur314929b2016-10-14 15:55:16 +110023};
24
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110025#define API_MIN_VERSION API_VERSION_1
26#define API_MAX_VERSION API_VERSION_2
27
28#define THIS_NAME "Mailbox Daemon"
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110029
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110030/* Argument Flags */
31#define FLAGS_NONE 0x00
32#define FLAGS_SHORT_LIFETIME 0x01
33
34/* BMC Event Notification */
Andrew Jefferyfab672b2018-11-01 17:12:09 +103035#define BMC_EVENT_PROTOCOL_RESET 0x01
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110036#define BMC_EVENT_WINDOW_RESET 0x02
Andrew Jefferyfab672b2018-11-01 17:12:09 +103037#define BMC_EVENT_ACK_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110038 BMC_EVENT_WINDOW_RESET)
39#define BMC_EVENT_FLASH_CTRL_LOST 0x40
40#define BMC_EVENT_DAEMON_READY 0x80
Andrew Jefferyfab672b2018-11-01 17:12:09 +103041#define BMC_EVENT_V1_MASK BMC_EVENT_PROTOCOL_RESET
42#define BMC_EVENT_V2_MASK (BMC_EVENT_PROTOCOL_RESET | \
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110043 BMC_EVENT_WINDOW_RESET | \
44 BMC_EVENT_FLASH_CTRL_LOST | \
45 BMC_EVENT_DAEMON_READY)
46
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110047/* Put polled file descriptors first */
48#define DBUS_FD 0
49#define MBOX_FD 1
50#define SIG_FD 2
51#define POLL_FDS 3 /* Number of FDs we poll on */
52#define LPC_CTRL_FD 3
Evan Lojewskif1e547c2019-03-14 14:34:33 +103053#define TOTAL_FDS 4
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110054
55#define MAPS_FLASH (1 << 0)
56#define MAPS_MEM (1 << 1)
57#define STATE_SUSPENDED (1 << 7)
Andrew Jeffery26558db2018-08-10 00:22:38 +093058
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110059enum mbox_state {
60 /* Still Initing */
61 UNINITIALISED = 0,
62 /* Active and LPC Maps Flash */
63 ACTIVE_MAPS_FLASH = MAPS_FLASH,
64 /* Suspended and LPC Maps Flash */
65 SUSPEND_MAPS_FLASH = STATE_SUSPENDED | MAPS_FLASH,
66 /* Active and LPC Maps Memory */
67 ACTIVE_MAPS_MEM = MAPS_MEM,
68 /* Suspended and LPC Maps Memory */
69 SUSPEND_MAPS_MEM = STATE_SUSPENDED | MAPS_MEM
Cyril Bur314929b2016-10-14 15:55:16 +110070};
71
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110072struct mbox_context {
Andrew Jeffery1e531af2018-08-07 13:32:57 +093073 enum api_version version;
74 const struct protocol_ops *protocol;
Andrew Jeffery5335f092018-08-09 14:56:08 +093075 const struct transport_ops *transport;
Evan Lojewskif1e547c2019-03-14 14:34:33 +103076 struct backend backend;
77
78 /* Commandline parameters */
79 const char *path;
Andrew Jeffery1e531af2018-08-07 13:32:57 +093080
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110081/* System State */
82 enum mbox_state state;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110083 struct pollfd fds[TOTAL_FDS];
84 sd_bus *bus;
85 bool terminate;
86 uint8_t bmc_events;
Andrew Jeffery55dede62017-04-24 16:13:06 +093087 uint8_t prev_seq;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110088
89/* Window State */
90 /* The window list struct containing all current "windows" */
91 struct window_list windows;
92 /* The window the host is currently pointed at */
93 struct window_context *current;
94 /* Is the current window a write one */
95 bool current_is_write;
96
97/* Memory & Flash State */
98 /* Reserved Memory Region */
99 void *mem;
100 /* Reserved Mem Size (bytes) */
101 uint32_t mem_size;
102 /* LPC Bus Base Address (bytes) */
103 uint32_t lpc_base;
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +1100104};
105
106#endif /* MBOX_H */