AM263x MCU+ SDK  08.03.00
sipc_notify_mailbox.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef SIPC_NOTIFY_MAILBOX_H_
34 #define SIPC_NOTIFY_MAILBOX_H_
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdint.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 /* this file has define's and inline function's to program the HW mailbox registers and SW queue structure */
45 #define MAILBOX_MAX_SW_QUEUE_STRUCT_SIZE (sizeof(SIPC_SwQueue))
46 
47 /* The HW mailbox only allows to trigger a interrupt on another core,
48  * the SIPC Notify needs ability to pass x byte message along with a interrupt
49  *
50  * Basically this mimics the functionality of HW mailbox with HW FIFO in AM243x SOC
51  *
52  * This needs to be in sync with the addresses being set for SW queue memory in soc/{soc}/sipc_notify_cfg.c
53  *
54  * The new queue has two more parameters i.e EleSize = Size of 1 queue element in words
55  * Qlength = total length of this Queue */
56 
62 typedef struct SIPC_SwQueue_
63 {
64  uint32_t rdIdx;
65  uint32_t wrIdx;
66  uint16_t EleSize ;
67  uint16_t Qlength ;
68  uint8_t *Qfifo;
69 } SIPC_SwQueue;
70 
71 /* Read from SW fifo within a mailbox */
72 static inline int32_t SIPC_mailboxRead(SIPC_SwQueue *swQ, uint8_t *Buff)
73 {
74  int32_t status = SystemP_FAILURE;
75 
76  volatile uint32_t rdIdx = swQ->rdIdx;
77  volatile uint32_t wrIdx = swQ->wrIdx;
78 
79  if(rdIdx < swQ->Qlength && wrIdx < swQ->Qlength)
80  {
81  /* If this condition meets then it means there is something in the fifo*/
82  if( rdIdx != wrIdx)
83  {
84  /* Copy EleSize bytes from Queue memory to the buffer */
85  memcpy(Buff, (swQ->Qfifo + (swQ->EleSize*rdIdx)),swQ->EleSize);
86 
87  rdIdx = (rdIdx+1)%swQ->Qlength;
88 
89  swQ->rdIdx = rdIdx;
90 
91  rdIdx = swQ->rdIdx; /* read back to ensure the update has reached the memory */
92 
93  #if defined(__aarch64__) || defined(__arm__)
94  __asm__( "dsb sy");
95  __asm__( "isb");
96  #endif
97 
98  status = SystemP_SUCCESS;
99  }
100  }
101 
102  return status;
103 }
104 
105 /* Write to SW fifo and trigger HW interrupt using HW mailbox */
106 static inline int32_t SIPC_mailboxWrite(uint32_t mailboxBaseAddr, uint32_t wrIntrBitPos, SIPC_SwQueue *swQ, uint8_t *Buff)
107 {
108  int32_t status = SystemP_FAILURE;
109 
110  volatile uint32_t rdIdx = swQ->rdIdx;
111  volatile uint32_t wrIdx = swQ->wrIdx;
112 
113  if(rdIdx < swQ->Qlength && wrIdx < swQ->Qlength)
114  {
115  if( ( (wrIdx+1)%swQ->Qlength ) != rdIdx )
116  {
117  volatile uint32_t *addr = (uint32_t *)mailboxBaseAddr;
118 
119  /* There is some space in the FIFO */
120 
121  memcpy((swQ->Qfifo + (swQ->EleSize*wrIdx)),Buff,swQ->EleSize);
122 
123  wrIdx = (wrIdx+1)%swQ->Qlength;
124 
125  swQ->wrIdx = wrIdx;
126 
127  wrIdx = swQ->wrIdx; /* read back to ensure the update has reached the memory */
128 
129  #if defined(__aarch64__) || defined(__arm__)
130  __asm__( "dsb sy");
131  __asm__( "isb");
132  #endif
133 
134  /* Trigger interrupt to other core */
135  *addr = (1U << (wrIntrBitPos));
136 
137  status = SystemP_SUCCESS;
138  }
139  }
140  return status;
141 }
142 
143 static inline void SIPC_mailboxClearAllInt(uint32_t mailboxBaseAddr)
144 {
145  volatile uint32_t *addr = (uint32_t *)mailboxBaseAddr;
146  *addr = 0x1111111;
147 }
148 
149 static inline uint32_t SIPC_mailboxGetPendingIntr(uint32_t mailboxBaseAddr)
150 {
151  volatile uint32_t *addr = (uint32_t *)mailboxBaseAddr;
152 
153  return *addr;
154 }
155 
156 static inline void SIPC_mailboxClearPendingIntr(uint32_t mailboxBaseAddr, uint32_t pendingIntr)
157 {
158  volatile uint32_t *addr = ( uint32_t *)mailboxBaseAddr;
159  *addr = pendingIntr;
160 }
161 
162 static inline uint32_t SIPC_mailboxIsPendingIntr(uint32_t pendingIntr, uint32_t coreId)
163 {
164  extern uint32_t gSIPCCoreIntrBitPos[];
165 
166  uint32_t isPending = 0;
167  isPending = pendingIntr & (1 << gSIPCCoreIntrBitPos[coreId]);
168  return isPending;
169 }
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /*SIPC_NOTIFY_MAILBOX_H_*/
176 
SIPC_mailboxIsPendingIntr
static uint32_t SIPC_mailboxIsPendingIntr(uint32_t pendingIntr, uint32_t coreId)
Definition: sipc_notify_mailbox.h:162
SIPC_SwQueue::wrIdx
uint32_t wrIdx
Definition: sipc_notify_mailbox.h:65
SIPC_SwQueue::rdIdx
uint32_t rdIdx
Definition: sipc_notify_mailbox.h:64
SIPC_mailboxWrite
static int32_t SIPC_mailboxWrite(uint32_t mailboxBaseAddr, uint32_t wrIntrBitPos, SIPC_SwQueue *swQ, uint8_t *Buff)
Definition: sipc_notify_mailbox.h:106
SIPC_SwQueue::Qfifo
uint8_t * Qfifo
Definition: sipc_notify_mailbox.h:68
SIPC_mailboxGetPendingIntr
static uint32_t SIPC_mailboxGetPendingIntr(uint32_t mailboxBaseAddr)
Definition: sipc_notify_mailbox.h:149
SIPC_SwQueue::Qlength
uint16_t Qlength
Definition: sipc_notify_mailbox.h:67
SIPC_SwQueue
SIPC swQ structure which holds the data pointer to a fifo Queue in HSM MBOX memory.
Definition: sipc_notify_mailbox.h:63
SystemP_SUCCESS
#define SystemP_SUCCESS
Return status when the API execution was successful.
Definition: SystemP.h:56
SystemP_FAILURE
#define SystemP_FAILURE
Return status when the API execution was not successful due to a failure.
Definition: SystemP.h:61
SIPC_SwQueue::EleSize
uint16_t EleSize
Definition: sipc_notify_mailbox.h:66
SIPC_mailboxClearPendingIntr
static void SIPC_mailboxClearPendingIntr(uint32_t mailboxBaseAddr, uint32_t pendingIntr)
Definition: sipc_notify_mailbox.h:156
SIPC_mailboxClearAllInt
static void SIPC_mailboxClearAllInt(uint32_t mailboxBaseAddr)
Definition: sipc_notify_mailbox.h:143
SIPC_mailboxRead
static int32_t SIPC_mailboxRead(SIPC_SwQueue *swQ, uint8_t *Buff)
Definition: sipc_notify_mailbox.h:72