1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the 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 "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * ======== GateAAMonitor.c ========
34 */
36 #include <xdc/std.h>
37 #include <xdc/runtime/Assert.h>
38 #include <xdc/runtime/Error.h>
39 #include <xdc/runtime/IGateProvider.h>
40 #include <xdc/runtime/Gate.h>
41 #include <xdc/runtime/Log.h>
42 #include <ti/sysbios/family/c64p/Cache.h>
43 #include <ti/sysbios/family/c64p/Hwi.h>
45 #include <ti/sdo/ipc/interfaces/IGateMPSupport.h>
47 #include "package/internal/GateAAMonitor.xdc.h"
49 #include <ti/sdo/ipc/_Ipc.h>
50 #include <ti/sdo/ipc/_SharedRegion.h>
52 /*
53 *************************************************************************
54 * Instance functions
55 *************************************************************************
56 */
58 /*
59 * ======== GateAAMonitor_Instance_init ========
60 */
61 Int GateAAMonitor_Instance_init(GateAAMonitor_Object *obj,
62 IGateProvider_Handle localGate,
63 const GateAAMonitor_Params *params,
64 Error_Block *eb)
65 {
66 /* Assert that params->sharedAddr is valid */
67 Assert_isTrue(
68 (UInt32)params->sharedAddr >= GateAAMonitor_SL2_RANGE_BASE &&
69 (UInt32)params->sharedAddr < GateAAMonitor_SL2_RANGE_MAX,
70 GateAAMonitor_A_invSharedAddr);
72 obj->localGate = localGate;
73 obj->sharedAddr = (Ptr)_Ipc_roundup(params->sharedAddr,
74 GateAAMonitor_CACHELINE_SIZE);
75 obj->nested = 0;
77 if (!params->openFlag) {
78 /*
79 * The processor that inits the AAM initializes the value
80 * to zero (e.g. no one is using it). The other processors
81 * must invalidate the memory in case it is in cache.
82 */
83 *(obj->sharedAddr) = 0;
84 Cache_wbInv((Ptr)obj->sharedAddr, GateAAMonitor_CACHELINE_SIZE,
85 Cache_Type_ALL, TRUE);
86 }
87 else {
88 /* Opening. */
89 Cache_inv((Ptr)obj->sharedAddr, GateAAMonitor_CACHELINE_SIZE,
90 Cache_Type_ALL, TRUE);
91 }
93 return (0);
94 }
96 /*
97 * ======== GateAAMonitor_enter ========
98 */
99 IArg GateAAMonitor_enter(GateAAMonitor_Object *obj)
100 {
101 IArg key;
103 key = IGateProvider_enter(obj->localGate);
105 /* If the gate object has already been entered, return the nested value */
106 obj->nested++;
107 if (obj->nested > 1) {
108 return (key);
109 }
111 /* Enter the monitor */
112 GateAAMonitor_getLock((Ptr)obj->sharedAddr);
114 return (key);
115 }
117 /*
118 * ======== GateAAMonitor_leave ========
119 * The sharedAddr must come from SL2 (shared L2 memory) so we only
120 * have to freeze L1D.
121 */
122 Void GateAAMonitor_leave(GateAAMonitor_Object *obj, IArg key)
123 {
124 Cache_Mode mode;
125 UInt hwiKey;
127 obj->nested--;
129 if (obj->nested == 0) {
130 /* disable interrupts before setting Cache to FREEZE */
131 hwiKey = Hwi_disable();
133 mode = Cache_setMode(Cache_Type_L1D, Cache_Mode_FREEZE);
135 /* Leave the critical region by setting address value to zero */
136 *(obj->sharedAddr) = 0;
138 Cache_setMode(Cache_Type_L1D, mode);
140 /* restore interrupts */
141 Hwi_restore(hwiKey);
142 }
144 IGateProvider_leave(obj->localGate, key);
145 }
147 /*
148 *************************************************************************
149 * Module functions
150 *************************************************************************
151 */
153 /*
154 * ======== GateAAMonitor_getReservedMask ========
155 */
156 Bits32 *GateAAMonitor_getReservedMask()
157 {
158 /* This gate doesn't allow reserving resources */
159 return (NULL);
160 }
162 /*
163 * ======== GatePeterson_sharedMemReq ========
164 */
165 SizeT GateAAMonitor_sharedMemReq(const IGateMPSupport_Params *params)
166 {
167 SizeT memReq;
169 memReq = (SizeT)(2 * GateAAMonitor_CACHELINE_SIZE);
171 return (memReq);
172 }
174 /*
175 * ======== GateAAMonitor_query ========
176 */
177 Bool GateAAMonitor_query(Int qual)
178 {
179 Bool rc;
181 switch (qual) {
182 case IGateProvider_Q_BLOCKING:
183 /* Depends on gate proxy? */
184 rc = FALSE;
185 break;
187 case IGateProvider_Q_PREEMPTING:
188 /* Depends on gate proxy? */
189 rc = TRUE;
190 break;
191 default:
192 rc = FALSE;
193 break;
194 }
196 return (rc);
197 }