tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / ixp / npe / IxNpeMhUnsolicitedCbMgr.c
1 /**
2  * @file IxNpeMhUnsolicitedCbMgr.c
3  *
4  * @author Intel Corporation
5  * @date 18 Jan 2002
6  *
7  * @brief This file contains the implementation of the private API for
8  * the Unsolicited Callback Manager module.
9  *
10  * 
11  * @par
12  * IXP400 SW Release version 2.0
13  * 
14  * -- Copyright Notice --
15  * 
16  * @par
17  * Copyright 2001-2005, Intel Corporation.
18  * All rights reserved.
19  * 
20  * @par
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  * 3. Neither the name of the Intel Corporation nor the names of its contributors
30  *    may be used to endorse or promote products derived from this software
31  *    without specific prior written permission.
32  * 
33  * @par
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
35  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
38  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  * 
46  * @par
47  * -- End of Copyright Notice --
48 */
49
50 /*
51  * Put the system defined include files required.
52  */
53
54
55 /*
56  * Put the user defined include files required.
57  */
58 #include "IxOsal.h"
59
60 #include "IxNpeMhMacros_p.h"
61
62 #include "IxNpeMhUnsolicitedCbMgr_p.h"
63
64
65 /*
66  * #defines and macros used in this file.
67  */
68
69 /*
70  * Typedefs whose scope is limited to this file.
71  */
72
73 /**
74  * @struct IxNpeMhUnsolicitedCallbackTable
75  *
76  * @brief This structure is used to maintain the list of registered
77  * callbacks.  One entry exists for each message ID, and a NULL entry will
78  * signify that no callback has been registered for that ID.
79  */
80
81 typedef struct
82 {
83     /** array of entries */
84     IxNpeMhCallback entries[IX_NPEMH_MAX_MESSAGE_ID + 1];
85 } IxNpeMhUnsolicitedCallbackTable;
86
87 /**
88  * @struct IxNpeMhUnsolicitedCbMgrStats
89  *
90  * @brief This structure is used to maintain statistics for the Unsolicited
91  * Callback Manager module.
92  */
93
94 typedef struct
95 {
96     UINT32 saves;      /**< callback table saves */
97     UINT32 overwrites; /**< callback table overwrites */
98 } IxNpeMhUnsolicitedCbMgrStats;
99
100 /*
101  * Variable declarations global to this file only.  Externs are followed by
102  * static variables.
103  */
104
105 PRIVATE IxNpeMhUnsolicitedCallbackTable
106 ixNpeMhUnsolicitedCallbackTables[IX_NPEMH_NUM_NPES];
107
108 PRIVATE IxNpeMhUnsolicitedCbMgrStats
109 ixNpeMhUnsolicitedCbMgrStats[IX_NPEMH_NUM_NPES];
110
111 /*
112  * Extern function prototypes.
113  */
114
115 /*
116  * Static function prototypes.
117  */
118
119 /*
120  * Function definition: ixNpeMhUnsolicitedCbMgrInitialize
121  */
122
123 void ixNpeMhUnsolicitedCbMgrInitialize (void)
124 {
125     IxNpeMhNpeId npeId = 0;
126     IxNpeMhUnsolicitedCallbackTable *table = NULL;
127     IxNpeMhMessageId messageId = 0;
128
129     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
130                      "ixNpeMhUnsolicitedCbMgrInitialize\n");
131
132     /* for each NPE ... */
133     for (npeId = 0; npeId < IX_NPEMH_NUM_NPES; npeId++)
134     {
135         /* initialise a pointer to the table for convenience */
136         table = &ixNpeMhUnsolicitedCallbackTables[npeId];
137
138         /* for each message ID ... */
139         for (messageId = IX_NPEMH_MIN_MESSAGE_ID;
140              messageId <= IX_NPEMH_MAX_MESSAGE_ID; messageId++)
141         {
142             /* initialise the callback for this message ID to NULL */
143             table->entries[messageId] = NULL;
144         }
145     }
146
147     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
148                      "ixNpeMhUnsolicitedCbMgrInitialize\n");
149 }
150
151 /*
152  * Function definition: ixNpeMhUnsolicitedCbMgrCallbackSave
153  */
154
155 void ixNpeMhUnsolicitedCbMgrCallbackSave (
156     IxNpeMhNpeId npeId,
157     IxNpeMhMessageId unsolicitedMessageId,
158     IxNpeMhCallback unsolicitedCallback)
159 {
160     IxNpeMhUnsolicitedCallbackTable *table = NULL;
161
162     /* initialise a pointer to the table for convenience */
163     table = &ixNpeMhUnsolicitedCallbackTables[npeId];
164
165     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Entering "
166                      "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
167
168     /* update statistical info */
169     ixNpeMhUnsolicitedCbMgrStats[npeId].saves++;
170
171     /* check if there is a callback already registered for this NPE and */
172     /* message ID */
173     if (table->entries[unsolicitedMessageId] != NULL)
174     {
175         /* if we are overwriting an existing callback */
176         if (unsolicitedCallback != NULL)
177         {
178             IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "Unsolicited callback "
179                              "overwriting existing callback for NPE ID %d "
180                              "message ID 0x%02X\n", npeId, unsolicitedMessageId);
181         }
182         else /* if we are clearing an existing callback */
183         {
184             IX_NPEMH_TRACE2 (IX_NPEMH_DEBUG, "NULL unsolicited callback "
185                              "clearing existing callback for NPE ID %d "
186                              "message ID 0x%02X\n", npeId, unsolicitedMessageId);
187         }
188
189         /* update statistical info */
190         ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites++;
191     }
192
193     /* save the callback into the table */
194     table->entries[unsolicitedMessageId] = unsolicitedCallback;
195
196     IX_NPEMH_TRACE0 (IX_NPEMH_FN_ENTRY_EXIT, "Exiting "
197                      "ixNpeMhUnsolicitedCbMgrCallbackSave\n");
198 }
199
200 /*
201  * Function definition: ixNpeMhUnsolicitedCbMgrCallbackRetrieve
202  */
203
204 void ixNpeMhUnsolicitedCbMgrCallbackRetrieve (
205     IxNpeMhNpeId npeId,
206     IxNpeMhMessageId unsolicitedMessageId,
207     IxNpeMhCallback *unsolicitedCallback)
208 {
209     IxNpeMhUnsolicitedCallbackTable *table = NULL;
210
211     /* initialise a pointer to the table for convenience */
212     table = &ixNpeMhUnsolicitedCallbackTables[npeId];
213
214     /* retrieve the callback from the table */
215     *unsolicitedCallback = table->entries[unsolicitedMessageId];
216 }
217
218 /*
219  * Function definition: ixNpeMhUnsolicitedCbMgrShow
220  */
221
222 void ixNpeMhUnsolicitedCbMgrShow (
223     IxNpeMhNpeId npeId)
224 {
225     /* show the unsolicited callback table save counter */
226     IX_NPEMH_SHOW ("Unsolicited callback table saves",
227                    ixNpeMhUnsolicitedCbMgrStats[npeId].saves);
228
229     /* show the unsolicited callback table overwrite counter */
230     IX_NPEMH_SHOW ("Unsolicited callback table overwrites",
231                    ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites);
232 }
233
234 /*
235  * Function definition: ixNpeMhUnsolicitedCbMgrShowReset
236  */
237
238 void ixNpeMhUnsolicitedCbMgrShowReset (
239     IxNpeMhNpeId npeId)
240 {
241     /* reset the unsolicited callback table save counter */
242     ixNpeMhUnsolicitedCbMgrStats[npeId].saves = 0;
243
244     /* reset the unsolicited callback table overwrite counter */
245     ixNpeMhUnsolicitedCbMgrStats[npeId].overwrites = 0;
246 }