/* * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. * * SPDX-License-Identifier: MIT */ #ifndef __MAILBOX_API_H__ #define __MAILBOX_API_H__ #if __cplusplus extern "C" { #endif #include #include #include "queue.h" #include "task.h" #include "mailbox-common.h" #include "mailbox-cmd.h" #include "drv_errno.h" #ifdef CONFIG_SOC_OLD_ARCH #include "mailbox-pl.h" #else #include "mailbox.h" #include "mailbox-irq.h" #endif /* Mailbox Driver ID Range Description * Direction ID Range ID Numbers Total ID Range Total ID Numbers * AO2ARMREE 0 ~ 63 64 0 ~ 242 243 * ARMREE2AO 64 ~ 127 64 * ARMTEE2AO 128 1 * DSPA2ARMREE 129 ~ 144 16 * DSPB2ARMREE 145 ~ 160 16 * ARMREE2DSPA 161 ~ 176 16 * ARMREE2DSPB 177 ~ 192 16 * M4A2ARMREE 193 ~ 200 8 * M4B2ARMREE 201 ~ 208 8 * ARMREE2M4A 209 ~ 216 8 * ARMREE2M4B 217 ~ 224 8 * DSPA2AO 225 ~ 228 4 * DSPB2AO 229 ~ 232 4 * AO2DSPA 233 ~ 236 4 * AO2DSPB 237 ~ 240 4 * ARMSEC2DSPA 241 1 * ARMSEC2DSPB 242 1 */ #define MBOX_BUF_LEN MBOX_DATA_SIZE #define MBOX_CH_ID_UNDEFINED 0xFF #define MBOX_CALL_MAX MAX_ENTRY_NUM #define ERR_MBOX(errno) (DRV_ERRNO_MAILBOX_BASE | errno) /* * mailbox channel information */ struct xMboxChan { uint8_t ucMboxChId; /* mbox channel ID */ QueueHandle_t xLock; /* mbox channel lock */ uint32_t ulSetAddr; /* mbox set addr */ uint32_t ulClrAddr; /* mbox clr addr */ uint32_t ulStatAddr; /* mbox stat addr */ uint32_t ulWrAddr; /* mbox write data addr */ uint32_t ulRdAddr; /* mbox read data addr */ }; /* * mailbox client channel information */ struct xClientMboxChan { uint8_t ucClientChId; /* mbox client channel ID */ struct xMboxChan *pxMboxChan; /* mbox channel information pointer */ }; /* * mailbox data information */ struct xMboxData { uint32_t ulCmd; /* mbox command that defined in mailbox_cmd.h */ void *pvTxbuf; /* mbox send buffer */ void *pvRxbuf; /* mbox receive buffer */ uint8_t ucTxSize; /* mbox send buffer size */ uint8_t ucRxSize; /* mbox receive buffer size */ }; struct xMboxIdTab { uint8_t ucClientChId; /* mbox client channel ID*/ uint8_t ucMboxChId; /* mbox channel ID */ }; #ifdef CONFIG_MAILBOX_SEND int iMboxTransData(struct xClientMboxChan *pxMboxChan, struct xMboxData *pxMboxData); #endif /* * Mailbox send message to remote * @param pxMboxChan, the mailbox client channel * @param pxMboxData, the mailbox data * @return 0, transfer success * not 0, transfer fail */ BaseType_t xMboxSendMsg(struct xClientMboxChan *pxMboxChan, struct xMboxData *pxMboxData); /* * Request destination mailbox channel used for transport * @param ucClientChId, mailbox remote client channel ID * @return, NULL, request client channel fail * NOT NULL, the pointer of requested client channel information */ struct xClientMboxChan *xMboxRequestChan(uint8_t ucClientChId); /* * Free destination mailbox channel used for transport * @param pxClientChan, the mailbox client channel pointer requested before * @return, 0, free mailbox channel success * positive, free mailbox channel fail with error NO. */ BaseType_t xMboxFreeChan(struct xClientMboxChan *pxClientChan); /* * Register mailbox callback function for client driver to receive message * @param ulChan, the mailbox channel client driver used to receive message * @param cmd, the mailbox command client driver used to communicate * @param arg, the callback function client driver used to call when mailbox * message is received * @param needFdBak, set to 1 if client driver need to send back message to * remote in callback function, or set to 0 if client driver need not * send back message to remote in callback function * @return, 0, register mailbox callback function success * positive, register mailbox callback function fail */ int xInstallRemoteMessageCallbackFeedBack(uint32_t ulChan, uint32_t cmd, void *(*handler)(void *arg), uint8_t needFdBak); /* * Unregister mailbox callback function for client driver to receive message * @param ulChan, the mailbox channel client driver used to receive message * @param cmd, the mailbox command client driver used to communicate * @return, 0, unregister mailbox callback function success * positive, unregister mailbox callback function fail */ int xUninstallRemoteMessageCallback(uint32_t ulChan, int32_t cmd); #if __cplusplus } #endif #endif