summaryrefslogtreecommitdiffstats
path: root/mbox.h
diff options
context:
space:
mode:
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>2017-03-28 10:47:43 +1100
committerSuraj Jitindar Singh <sjitindarsingh@gmail.com>2017-04-11 11:41:54 +1000
commite39c91637337fc1afc54fe8e215f1493395601a3 (patch)
tree0af6bb466ed1ca0afcb03e568a3a98da5723c06d /mbox.h
parent2dff340a846068f33a0de171a75d4187bc189ea3 (diff)
downloadphosphor-mboxd-e39c91637337fc1afc54fe8e215f1493395601a3.tar.gz
phosphor-mboxd-e39c91637337fc1afc54fe8e215f1493395601a3.zip
mboxd: Update mboxd to implement protocol V2 and add dbus support
Version 2 of the mbox protocol contains a few changes such as: - All sizes are in block size - Adds an erase command - Adds new response codes - Adds new BMC events - Open windows commands now take a size directive Update the mailbox daemon to support version 2 of the protocol which includes implementing all of the V2 functionality. Also entirely refactor the mboxd.c code to make it more modular improving readability and maintainability. At the same time improve the functionality by adding: - Multiple windows in the daemon (still only one active window) to cache flash contents - Implement a dbus interface to allow interaction with the daemon - Handle sigterm and sigint and terminate cleanly The previous implementation utilised the entire reserved memory region. Update the daemon so that on the command line the number of windows and the size of each which the reserved memory region will be split into can be specified. The reserved memory region is then divided between the windows, however there can still only be one "active" window at a time. The daemon uses these windows to cache the flash contents meaning the flash doesn't have to be copied when the host requests access assuming the daemon already has a copy. A dbus interface is added so that commands can be sent to the daemon to control it's operation from the bmc. These include suspending and resuming the daemon to synchronise flash access, telling the daemon to point the lpc mapping back to flash and telling the daemon when the flash has been modified out from under it. Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com> Change-Id: I10be01a395c2bec437cf2c825fdd144580b60dbc
Diffstat (limited to 'mbox.h')
-rw-r--r--mbox.h193
1 files changed, 154 insertions, 39 deletions
diff --git a/mbox.h b/mbox.h
index f772558..d9a8d03 100644
--- a/mbox.h
+++ b/mbox.h
@@ -1,53 +1,168 @@
-/* Copyright 2016 IBM
+/*
+ * Copyright 2016 IBM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*
*/
-#define MBOX_C_RESET_STATE 0x01
-#define MBOX_C_GET_MBOX_INFO 0x02
-#define MBOX_C_GET_FLASH_INFO 0x03
-#define MBOX_C_READ_WINDOW 0x04
-#define MBOX_C_CLOSE_WINDOW 0x05
-#define MBOX_C_WRITE_WINDOW 0x06
-#define MBOX_C_WRITE_DIRTY 0x07
-#define MBOX_C_WRITE_FENCE 0x08
-#define MBOX_C_ACK 0x09
-#define MBOX_C_COMPLETED_COMMANDS 0x0a
-
-#define MBOX_R_SUCCESS 0x01
-#define MBOX_R_PARAM_ERROR 0x02
-#define MBOX_R_WRITE_ERROR 0x03
-#define MBOX_R_SYSTEM_ERROR 0x4
-#define MBOX_R_TIMEOUT 0x05
-
-#define MBOX_HOST_PATH "/dev/aspeed-mbox"
-#define MBOX_HOST_TIMEOUT_SEC 1
-#define MBOX_DATA_BYTES 11
-#define MBOX_REG_BYTES 16
-#define MBOX_HOST_BYTE 14
-#define MBOX_BMC_BYTE 15
-
-struct mbox_msg {
- uint8_t command;
- uint8_t seq;
- uint8_t data[MBOX_DATA_BYTES];
- uint8_t response;
+#ifndef MBOX_H
+#define MBOX_H
+
+#include <mtd/mtd-abi.h>
+#include <systemd/sd-bus.h>
+
+enum api_version {
+ API_VERSION_INVAL = 0,
+ API_VERSION_1 = 1,
+ API_VERSION_2 = 2
+};
+
+#define API_MIN_VERSION API_VERSION_1
+#define API_MAX_VERSION API_VERSION_2
+
+#define THIS_NAME "Mailbox Daemon"
+#define SUB_VERSION 0
+
+/* Command Values */
+#define MBOX_C_RESET_STATE 0x01
+#define MBOX_C_GET_MBOX_INFO 0x02
+#define MBOX_C_GET_FLASH_INFO 0x03
+#define MBOX_C_READ_WINDOW 0x04
+#define MBOX_C_CLOSE_WINDOW 0x05
+#define MBOX_C_WRITE_WINDOW 0x06
+#define MBOX_C_WRITE_DIRTY 0x07
+#define MBOX_C_WRITE_FLUSH 0x08
+#define MBOX_C_ACK 0x09
+#define MBOX_C_WRITE_ERASE 0x0a
+#define NUM_MBOX_CMDS MBOX_C_WRITE_ERASE
+
+/* Response Values */
+#define MBOX_R_SUCCESS 0x01
+#define MBOX_R_PARAM_ERROR 0x02
+#define MBOX_R_WRITE_ERROR 0x03
+#define MBOX_R_SYSTEM_ERROR 0x04
+#define MBOX_R_TIMEOUT 0x05
+#define MBOX_R_BUSY 0x06
+#define MBOX_R_WINDOW_ERROR 0x07
+
+/* Argument Flags */
+#define FLAGS_NONE 0x00
+#define FLAGS_SHORT_LIFETIME 0x01
+
+/* BMC Event Notification */
+#define BMC_EVENT_REBOOT 0x01
+#define BMC_EVENT_WINDOW_RESET 0x02
+#define BMC_EVENT_ACK_MASK (BMC_EVENT_REBOOT | \
+ BMC_EVENT_WINDOW_RESET)
+#define BMC_EVENT_FLASH_CTRL_LOST 0x40
+#define BMC_EVENT_DAEMON_READY 0x80
+#define BMC_EVENT_V1_MASK BMC_EVENT_REBOOT
+#define BMC_EVENT_V2_MASK (BMC_EVENT_REBOOT | \
+ BMC_EVENT_WINDOW_RESET | \
+ BMC_EVENT_FLASH_CTRL_LOST | \
+ BMC_EVENT_DAEMON_READY)
+
+/* MBOX Registers */
+#define MBOX_HOST_PATH "/dev/aspeed-mbox"
+#define MBOX_HOST_TIMEOUT_SEC 1
+#define MBOX_ARGS_BYTES 11
+#define MBOX_REG_BYTES 16
+#define MBOX_HOST_EVENT 14
+#define MBOX_BMC_EVENT 15
+
+#define BLOCK_SIZE_SHIFT_V1 12 /* 4K */
+
+/* Window Dirty/Erase bytemap masks */
+#define WINDOW_CLEAN 0x00
+#define WINDOW_DIRTY 0x01
+#define WINDOW_ERASED 0x02
+
+/* Put polled file descriptors first */
+#define DBUS_FD 0
+#define MBOX_FD 1
+#define SIG_FD 2
+#define POLL_FDS 3 /* Number of FDs we poll on */
+#define LPC_CTRL_FD 3
+#define MTD_FD 4
+#define TOTAL_FDS 5
+
+#define MAPS_FLASH (1 << 0)
+#define MAPS_MEM (1 << 1)
+#define STATE_SUSPENDED (1 << 7)
+enum mbox_state {
+ /* Still Initing */
+ UNINITIALISED = 0,
+ /* Active and LPC Maps Flash */
+ ACTIVE_MAPS_FLASH = MAPS_FLASH,
+ /* Suspended and LPC Maps Flash */
+ SUSPEND_MAPS_FLASH = STATE_SUSPENDED | MAPS_FLASH,
+ /* Active and LPC Maps Memory */
+ ACTIVE_MAPS_MEM = MAPS_MEM,
+ /* Suspended and LPC Maps Memory */
+ SUSPEND_MAPS_MEM = STATE_SUSPENDED | MAPS_MEM
+};
+
+#define FLASH_OFFSET_UNINIT 0xFFFFFFFF
+
+struct window_context {
+ void *mem; /* Portion of Reserved Memory Region */
+ uint32_t flash_offset; /* Flash area the window maps (bytes) */
+ uint32_t size; /* Window Size (bytes) power-of-2 */
+ uint8_t *dirty_bmap; /* Bytemap of the dirty/erased state */
+ uint32_t age; /* Used for LRU eviction scheme */
};
-union mbox_regs {
- char raw[MBOX_REG_BYTES];
- struct mbox_msg msg;
+struct window_list {
+ uint32_t num;
+ uint32_t max_age;
+ uint32_t default_size;
+ struct window_context *window;
};
+struct mbox_context {
+/* System State */
+ enum mbox_state state;
+ enum api_version version;
+ struct pollfd fds[TOTAL_FDS];
+ sd_bus *bus;
+ bool terminate;
+ uint8_t bmc_events;
+
+/* Window State */
+ /* The window list struct containing all current "windows" */
+ struct window_list windows;
+ /* The window the host is currently pointed at */
+ struct window_context *current;
+ /* Is the current window a write one */
+ bool current_is_write;
+
+/* Memory & Flash State */
+ /* Reserved Memory Region */
+ void *mem;
+ /* Reserved Mem Size (bytes) */
+ uint32_t mem_size;
+ /* LPC Bus Base Address (bytes) */
+ uint32_t lpc_base;
+ /* Flash size from command line (bytes) */
+ uint32_t flash_size;
+ /* Bytemap of the erased state of the entire flash */
+ uint8_t *flash_bmap;
+ /* Erase size (as a shift) */
+ uint32_t erase_size_shift;
+ /* Block size (as a shift) */
+ uint32_t block_size_shift;
+ /* Actual Flash Info */
+ struct mtd_info_user mtd_info;
+};
+#endif /* MBOX_H */
OpenPOWER on IntegriCloud