developer | e5e687d | 2023-08-08 16:05:33 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Copyright (c) 2023 MediaTek Inc. All Rights Reserved. |
| 4 | * |
| 5 | * Author: Ren-Ting Wang <ren-ting.wang@mediatek.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef _TOPS_MBOX_H_ |
| 9 | #define _TOPS_MBOX_H_ |
| 10 | |
| 11 | #include <linux/list.h> |
| 12 | |
| 13 | #include "mbox_id.h" |
| 14 | #include "tops.h" |
| 15 | |
| 16 | /* mbox device macros */ |
| 17 | #define MBOX_DEV(core_id, cmd) \ |
| 18 | .core = core_id, \ |
| 19 | .cmd_id = cmd, |
| 20 | |
| 21 | #define MBOX_SEND_DEV(core_id, cmd) \ |
| 22 | { \ |
| 23 | MBOX_DEV(core_id, cmd) \ |
| 24 | } |
| 25 | |
| 26 | #define MBOX_SEND_MGMT_DEV(cmd) \ |
| 27 | MBOX_SEND_DEV(CORE_MGMT, MBOX_AP2CM_CMD_ ## cmd) |
| 28 | |
| 29 | #define MBOX_SEND_OFFLOAD_DEV(core_id, cmd) \ |
| 30 | MBOX_SEND_DEV(CORE_OFFLOAD_ ## core_id, MBOX_AP2CX_CMD_ ## cmd) |
| 31 | |
| 32 | #define MBOX_RECV_DEV(core_id, cmd, handler) \ |
| 33 | { \ |
| 34 | MBOX_DEV(core_id, cmd) \ |
| 35 | .mbox_handler = handler, \ |
| 36 | } |
| 37 | |
| 38 | #define MBOX_RECV_MGMT_DEV(cmd, handler) \ |
| 39 | MBOX_RECV_DEV(CORE_MGMT, MBOX_CM2AP_CMD_ ## cmd, handler) |
| 40 | |
| 41 | #define MBOX_RECV_OFFLOAD_DEV(core_id, cmd, handler) \ |
| 42 | MBOX_RECV_DEV(CORE_OFFLOAD_ ## core_id, MBOX_CX2AP_CMD_ ## cmd, handler) |
| 43 | |
| 44 | /* Base Address */ |
| 45 | #define MBOX_TOP_BASE (0x010000) |
| 46 | #define MBOX_CLUST0_BASE (0x510000) |
| 47 | |
| 48 | /* TOP Mailbox */ |
| 49 | #define TOPS_TOP_CM_SLOT (MBOX_TOP_BASE + 0x000) |
| 50 | #define TOPS_TOP_AP_SLOT (MBOX_TOP_BASE + 0x004) |
| 51 | |
| 52 | #define TOPS_TOP_AP_TO_CM_CMD_SET (MBOX_TOP_BASE + 0x200) |
| 53 | #define TOPS_TOP_AP_TO_CM_CMD_CLR (MBOX_TOP_BASE + 0x204) |
| 54 | #define TOPS_TOP_CM_TO_AP_CMD_SET (MBOX_TOP_BASE + 0x21C) |
| 55 | #define TOPS_TOP_CM_TO_AP_CMD_CLR (MBOX_TOP_BASE + 0x220) |
| 56 | |
| 57 | #define TOPS_TOP_AP_TO_CM_MSG_N(n) (MBOX_TOP_BASE + 0x208 + 0x4 * (n)) |
| 58 | #define TOPS_TOP_CM_TO_AP_MSG_N(n) (MBOX_TOP_BASE + 0x224 + 0x4 * (n)) |
| 59 | |
| 60 | /* CLUST Mailbox */ |
| 61 | #define TOPS_CLUST0_CX_SLOT(x) (MBOX_CLUST0_BASE + (0x4 * (x))) |
| 62 | #define TOPS_CLUST0_CM_SLOT (MBOX_CLUST0_BASE + 0x10) |
| 63 | #define TOPS_CLUST0_AP_SLOT (MBOX_CLUST0_BASE + 0x14) |
| 64 | |
| 65 | #define TOPS_CLUST0_CX_TO_CY_CMD_SET(x, y) \ |
| 66 | (MBOX_CLUST0_BASE + 0x100 + ((x) * 0x200) + ((y) * 0x40)) |
| 67 | #define TOPS_CLUST0_CX_TO_CY_CMD_CLR(x, y) \ |
| 68 | (MBOX_CLUST0_BASE + 0x104 + ((x) * 0x200) + ((y) * 0x40)) |
| 69 | #define TOPS_CLUST0_CX_TO_CM_CMD_SET(x) \ |
| 70 | (MBOX_CLUST0_BASE + 0x200 + ((x) * 0x200)) |
| 71 | #define TOPS_CLUST0_CX_TO_CM_CMD_CLR(x) \ |
| 72 | (MBOX_CLUST0_BASE + 0x204 + ((x) * 0x200)) |
| 73 | #define TOPS_CLUST0_CX_TO_AP_CMD_SET(x) \ |
| 74 | (MBOX_CLUST0_BASE + 0x240 + ((x) * 0x200)) |
| 75 | #define TOPS_CLUST0_CX_TO_AP_CMD_CLR(x) \ |
| 76 | (MBOX_CLUST0_BASE + 0x244 + ((x) * 0x200)) |
| 77 | #define TOPS_CLUST0_CM_TO_CX_CMD_SET(x) \ |
| 78 | (MBOX_CLUST0_BASE + 0x900 + ((x) * 0x40)) |
| 79 | #define TOPS_CLUST0_CM_TO_CX_CMD_CLR(x) \ |
| 80 | (MBOX_CLUST0_BASE + 0x904 + ((x) * 0x40)) |
| 81 | #define TOPS_CLUST0_AP_TO_CX_CMD_SET(x) \ |
| 82 | (MBOX_CLUST0_BASE + 0xB00 + ((x) * 0x40)) |
| 83 | #define TOPS_CLUST0_AP_TO_CX_CMD_CLR(x) \ |
| 84 | (MBOX_CLUST0_BASE + 0xB04 + ((x) * 0x40)) |
| 85 | |
| 86 | #define TOPS_CLUST0_CX_TO_CY_MSG_N(x, y, n) \ |
| 87 | (MBOX_CLUST0_BASE + 0x108 + ((n) * 0x4) + ((x) * 0x200) + ((y) * 0x40)) |
| 88 | #define TOPS_CLUST0_CX_TO_CM_MSG_N(x, n) \ |
| 89 | (MBOX_CLUST0_BASE + 0x208 + ((n) * 0x4) + ((x) * 0x200)) |
| 90 | #define TOPS_CLUST0_CX_TO_AP_MSG_N(x, n) \ |
| 91 | (MBOX_CLUST0_BASE + 0x248 + ((n) * 0x4) + ((x) * 0x200)) |
| 92 | #define TOPS_CLUST0_CM_TO_CX_MSG_N(x, n) \ |
| 93 | (MBOX_CLUST0_BASE + 0x908 + ((n) * 0x4) + ((x) * 0x40)) |
| 94 | #define TOPS_CLUST0_AP_TO_CX_MSG_N(x, n) \ |
| 95 | (MBOX_CLUST0_BASE + 0xB08 + ((n) * 0x4) + ((x) * 0x40)) |
| 96 | |
| 97 | #define MBOX_TOP_MBOX_FROM_C0 (0x1) |
| 98 | #define MBOX_TOP_MBOX_FROM_C1 (0x2) |
| 99 | #define MBOX_TOP_MBOX_FROM_C2 (0x4) |
| 100 | #define MBOX_TOP_MBOX_FROM_C3 (0x8) |
| 101 | #define MBOX_TOP_MBOX_FROM_AP (0x10) |
| 102 | #define MBOX_TOP_MBOX_FROM_CM (0x20) /* TODO: need DE update */ |
| 103 | |
| 104 | #define MBOX_CLUST0_MBOX_FROM_C0 (0x1) |
| 105 | #define MBOX_CLUST0_MBOX_FROM_C1 (0x2) |
| 106 | #define MBOX_CLUST0_MBOX_FROM_C2 (0x4) |
| 107 | #define MBOX_CLUST0_MBOX_FROM_C3 (0x8) |
| 108 | #define MBOX_CLUST0_MBOX_FROM_CM (0x10) |
| 109 | #define MBOX_CLUST0_MBOX_FROM_AP (0x20) |
| 110 | |
| 111 | struct mailbox_msg; |
| 112 | struct mailbox_dev; |
| 113 | enum mbox_msg_cnt; |
| 114 | |
| 115 | typedef void (*mbox_ret_func_t)(void *priv, struct mailbox_msg *msg); |
| 116 | typedef enum mbox_msg_cnt (*mbox_handler_func_t)(struct mailbox_dev *mdev, |
| 117 | struct mailbox_msg *msg); |
| 118 | |
| 119 | enum mbox_act { |
| 120 | MBOX_SEND, |
| 121 | MBOX_RECV, |
| 122 | MBOX_ACT_MAX, |
| 123 | }; |
| 124 | |
| 125 | enum mbox_msg_cnt { |
| 126 | MBOX_NO_RET_MSG, |
| 127 | MBOX_RET_MSG1, |
| 128 | MBOX_RET_MSG2, |
| 129 | MBOX_RET_MSG3, |
| 130 | MBOX_RET_MSG4, |
| 131 | }; |
| 132 | |
| 133 | struct mailbox_msg { |
| 134 | u32 msg1; |
| 135 | u32 msg2; |
| 136 | u32 msg3; |
| 137 | u32 msg4; |
| 138 | }; |
| 139 | |
| 140 | struct mailbox_dev { |
| 141 | struct list_head list; |
| 142 | enum core_id core; |
| 143 | mbox_handler_func_t mbox_handler; |
| 144 | void *priv; |
| 145 | u8 cmd_id; |
| 146 | }; |
| 147 | |
| 148 | int mbox_send_msg_no_wait_irq(struct mailbox_dev *mdev, struct mailbox_msg *msg); |
| 149 | int mbox_send_msg_no_wait(struct mailbox_dev *mdev, struct mailbox_msg *msg); |
| 150 | int mbox_send_msg(struct mailbox_dev *mdev, struct mailbox_msg *msg, void *priv, |
| 151 | mbox_ret_func_t ret_handler); |
| 152 | int register_mbox_dev(enum mbox_act act, struct mailbox_dev *mdev); |
| 153 | int unregister_mbox_dev(enum mbox_act act, struct mailbox_dev *mdev); |
| 154 | void mtk_tops_mbox_clear_all_cmd(void); |
| 155 | int mtk_tops_mbox_init(void); |
| 156 | void mtk_tops_mbox_exit(void); |
| 157 | #endif /* _TOPS_MBOX_H_ */ |