source: svn/trunk/newcon3bcm2_21bu/magnum/commonutils/mrc/7552/bmrc_monitor.h

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 16.5 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bmrc_monitor.h $
11 * $brcm_Revision: Hydra_Software_Devel/11 $
12 * $brcm_Date: 1/13/11 5:20p $
13 *
14 * Module Description:
15 *
16 * Implementation of the Realtime Memory Monitor for 7038
17 *
18 * Revision History:
19 *
20 * $brcm_Log: /magnum/commonutils/mrc/7125/bmrc_monitor.h $
21 *
22 * Hydra_Software_Devel/11   1/13/11 5:20p albertl
23 * SW7422-168: Default number of checkers set to -1 in
24 * BMRC_Monitor_Settings, handled as maximum available.
25 *
26 * Hydra_Software_Devel/10   1/12/11 3:09p albertl
27 * SW7422-168: Added comments for BMRC_Monitor_Settings.
28 *
29 * Hydra_Software_Devel/9   1/12/11 2:50p albertl
30 * SW7422-168: Changed BMRC_Monitor_Open to take settings structure.
31 * Removed BMRC_Monitor_SetSettings().  Added ability to configure how
32 * many checkers BMRC_Monitor uses to support more than one monitor on
33 * same MEMC.
34 *
35 * Hydra_Software_Devel/8   12/6/10 6:16p albertl
36 * SW7405-3892: Added ability to configure MRC violation behavior.
37 *
38 * Hydra_Software_Devel/7   6/30/10 6:11p albertl
39 * SW7405-4047: Added BMRC_Monitor_JailByFilename.
40 *
41 * Hydra_Software_Devel/6   3/2/10 1:25p erickson
42 * SW7405-3892: add BMRC_Monitor_PrintClients for debug, fix
43 * BMRC_Monitor_RemoveCustomTag name, add sample code for blocking
44 * unwanted kernel writes
45 *
46 * Hydra_Software_Devel/5   4/3/06 4:25p albertl
47 * PR20489:  Added BMRC_Monitor_JailDefault function.
48 *
49 * Hydra_Software_Devel/4   3/1/06 5:16p albertl
50 * PR18701:  Updated to match include latest RMM updates.
51 *
52 * Hydra_Software_Devel/3   8/4/05 6:50p albertl
53 * PR13641:  Fixed incorrect PR numbers in chagelog.
54 *
55 * Hydra_Software_Devel/1   8/1/05 10:14p albertl
56 * PR13641:  Initial Revision, based on RMM module.
57 *
58 ***************************************************************************/
59#ifndef BMRC_MONITOR_H_
60#define BMRC_MONITOR_H_
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65#include "bint.h"
66#include "bchp.h"
67#include "bmem.h"
68#include "bmrc.h"
69
70/*=Module Overview: ********************************************************
71BMRC_Monitor provides a way to monitor which hardware clients access certain blocks of memory.
72BMRC_Monitor uses the Address Range Checker (ARC) hardware which is a feature of the memory controller (MEMC).
73It does this via the BMRC module.
74
75This module easily integrates with magnum's memory manager (BMEM), which automatically configures
76clients based on BMEM_Alloc allocations, using the debug tag filename to associate a memory block
77with a certain set of MEMC clients.
78
79Because there are limited ARC's on each chip, BMRC_Monitor performs a combine operation on all BMRC_Monitor
80regions and clients. The end result is that multiple blocks and hardware clients may be combined into a
81single region. This limits the accuracy of the check. Not every bad memory access can be caught.
82
83To print the final BMRC_Monitor configuration, enable DBG's BDBG_eMsg Level for the BMRC_Monitor module and
84call BMRC_Monitor_JailUpdate.  For Settop API, set msg_modules=mem_monitor.
85
86Example:
87This shows the default configuration for BMRC_Monitor using the automatic configuration
88from BMEM. Error checking code is ommited for the sake of simplicity.
89
90void main(void)
91{
92        BMRC_Monitor_Handle hMonitor;
93        BMEM_Handle heap;
94        BREG_Handle reg;
95        BINT_Handle isr;
96        BCHP_Handle chp;
97        BMRC_Handle mrc;
98        BERR_Code rc;
99        static BMEM_MonitorInterface interface;
100
101        .... Initialize MemoryManager, RegisterInterface, InterruptInterface, ChipInterface, and MemoryRangeChecker ...
102
103        rc = BMRC_Monitor_Open(&hMonitor, reg, isr, chp, mrc, 0, 256 * 1024 * 1024); ... Control all 256MBytes window ...
104        rc = BMRC_Monitor_GetMemoryInterface(hMonitor, &interface);
105        rc = BMEM_InstallMonitor(heap, &interface);
106}
107
108This shows the use of a jail for debugging a specific client:
109        BMRC_Monitor_Handle hMonitor;
110        BMEM_Handle heap;
111        BREG_Handle reg;
112        BINT_Handle isr;
113        BCHP_Handle chp;
114        BERR_Code rc;
115        static BMEM_MonitorInterface interface;
116
117        .... Initialize MemoryManager, RegisterInterface, InterruptInterface and ChipInterface ...
118
119        rc = BMRC_Monitor_Open(&hMonitor, reg, isr, chp, mrc, 0, 256 * 1024 * 1024); ... Control all 256MBytes window ...
120        rc = BMRC_Monitor_GetMemoryInterface(hMonitor, &interface);
121        rc = BMEM_InstallMonitor(heap, &interface);
122        ... Performing AVD debug, so optimize range checking for AVD ...
123        BMRC_Monitor_JailAdd(hMonitor, BRMM_CLIENT_AVD_BLK_0);
124        BMRC_Monitor_JailAdd(hMonitor, BRMM_CLIENT_AVD_ILA_0);
125        BMRC_Monitor_JailAdd(hMonitor, BRMM_CLIENT_AVD_OLA_0);
126        BMRC_Monitor_JailAdd(hMonitor, BRMM_CLIENT_AVD_CAB_0);
127        BMRC_Monitor_JailAdd(hMonitor, BRMM_CLIENT_AVD_SYM_0);
128        BMRC_Monitor_JailUpdate(hMonitor);
129}
130
131
132See Also:
133        BMEM_InstallMonitor
134        BRMM_Open
135****************************************************************************/
136
137/*
138 * Summary this type is used to specify memory client
139 */
140typedef unsigned BMRC_Monitor_MemoryClientId;
141
142/*
143 * Summary this type is used to specify instance of the memory monitor
144 */
145typedef struct BMRC_P_MonitorContext *BMRC_Monitor_Handle;
146
147typedef struct BMRC_Monitor_Settings
148{
149        BMRC_AccessType eKernelBlockMode;    /* blocking mode when violations occur for kernel memory */
150        BMRC_AccessType eBlockMode;          /* blocking mode when violations occur for non-kernel memory */
151        uint32_t        ulNumCheckersToUse;  /* number of hardware checkers used by this instance of mrc monitor */
152} BMRC_Monitor_Settings;
153
154/***************************************************************************
155Summary:
156        Opens a realtime memory monitor
157
158Description:
159        You may create only one instance of RMM per system.
160
161Returns:
162        BERR_SUCCESS - Memory monitor was opened.
163
164See Also:
165        BMRC_Close
166****************************************************************************/
167BERR_Code BMRC_Monitor_Open(
168                BMRC_Monitor_Handle *phMonitor,   /* [out] this argument is used to return instance (handle) of memory monitor */
169                BREG_Handle hReg,                 /* RegisterInterface handle */
170                BINT_Handle iIsr,                 /* InterruptInterface handle */
171                BCHP_Handle hChp,                 /* ChipInterface handle */
172                BMRC_Handle hMrc,                 /* Memory Range Checker Handle */
173                uint32_t ulMemLow,                /* lowest address to control by the memory monitor, usually 0 */
174                uint32_t ulMemHigh,               /* highest address to control by the memory monitor, usualy 256*2^20 - 1 */
175                BMRC_Monitor_Settings *pSettings  /* monitor configuration settings.  use NULL for default settings. */
176                );
177
178/***************************************************************************
179Summary:
180        Closes memory monitor
181
182Description:
183        This function is used to release resources allocated by
184        BMRC_Monitor_Open.
185
186Returns:
187        N/A
188
189See Also:
190        BMRC_Open
191****************************************************************************/
192void BMRC_Monitor_Close(
193                BMRC_Monitor_Handle hMonitor /* Instance of the memory monitor */
194                );
195
196/***************************************************************************
197Summary:
198        Gets default settings for a MRC Monitor
199
200Description:
201        This function gets the default configuration settings for a MRC
202        Monitor by filling in pDefSettings.  It will fill the usMaxNumCheckers
203        with the value of -1 which indicates the monitor will use the maximum
204        available number of hardware checkers.  It can be overridden to specify
205        a number less than that.
206
207Returns:
208        N/A
209
210See Also:
211        BMRC_Monitor_Open
212****************************************************************************/
213BERR_Code
214BMRC_Monitor_GetDefaultSettings(
215                BMRC_Monitor_Settings *pDefSettings
216                );
217
218/***************************************************************************
219Summary:
220        Gets current settings for a MRC Monitor
221
222Description:
223        This function gets the current configuration settings for a MRC
224        Monitor by filling in pDefSettings.
225
226Returns:
227        N/A
228
229See Also:
230        BMRC_Monitor_Open
231****************************************************************************/
232BERR_Code
233BMRC_Monitor_GetSettings(
234                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
235                BMRC_Monitor_Settings *pSettings
236                );
237
238/***************************************************************************
239Summary:
240        Returns BMEM_MonitorInterface which is passed into BMEM_InstallMonitor
241        for automatic configuration.
242
243Description:
244        If your system uses multiple instances of BMEM, you can pass the
245        BMEM_MonitorInterface into each one.
246
247        BMEM_MonitorInterface is passed to BMEM by reference and so it is the
248        application's responsibility to insure that the instance of
249        BMEM_MonitorInterface remains intact all the time while the interface
250        can be referenced. For example, do not use an instance of
251        BMEM_MonitorInterface which is allocated as a function's local variable.
252
253
254Returns:
255        BERR_SUCCESS - Memory monitor was opened.
256
257****************************************************************************/
258BERR_Code
259BMRC_Monitor_GetMemoryInterface(
260                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
261                BMEM_MonitorInterface *pInterface /* [out] memory interface */
262                );
263
264/***************************************************************************
265Summary:
266        Resets jail to default configuration.
267
268Description:
269        This function is used to reset the "jail" to its default configuration.
270        It will reset all changes to the jail made after the module was
271        initialized and replace the jail client list with the standard default
272        hardware client list.  User needs to call function BMRC_Monitor_JailUpdate
273        before changes take effect.
274
275Returns:
276        BERR_SUCCESS - Memory monitor was opened.
277
278See also:
279        BMRC_Monitor_JailUpdate
280        BMRC_Monitor_JailAdd
281        BMRC_Monitor_JailRemove
282
283****************************************************************************/
284BERR_Code
285BMRC_Monitor_JailDefault(
286                BMRC_Monitor_Handle hMonitor /* Instance of the memory monitor */
287                );
288
289/***************************************************************************
290Summary:
291        Adds memory client associated with a filename into the jail.
292
293Description:
294        This function is used to add memory clients that are associated with a filename
295        to the "jail".  These client would only be able to access memory blocks allocated by
296        the file. User needs to call function BMRC_Monitor_JailUpdate before changes take effect.
297
298Note:
299        Current implementation uses the same rules for all clients which are "jailed".
300
301Returns:
302        BERR_SUCCESS - Memory monitor was opened.
303
304See also:
305        BMRC_Monitor_JailAdd
306        BMRC_Monitor_JailUpdate
307        BMRC_Monitor_JailRemove
308
309****************************************************************************/
310BERR_Code BMRC_Monitor_JailByFilename(
311                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
312                const char *filename /* filename  */
313                );
314
315/***************************************************************************
316Summary:
317        Adds memory client into the jail.
318
319Description:
320        This function is used to add memory client to the "jail", such client would be able
321        to access memory blocks which are allocated only to the given client. User needs
322        to call function BMRC_Monitor_JailUpdate before changes take effect.
323
324Note:
325        Current implementation uses the same rules for all clients which are "jailed".
326
327Returns:
328        BERR_SUCCESS - Memory monitor was opened.
329
330See also:
331        BMRC_Monitor_JailUpdate
332        BMRC_Monitor_JailRemove
333
334****************************************************************************/
335BERR_Code BMRC_Monitor_JailAdd(
336                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
337                BMRC_Monitor_MemoryClientId client /* id of the memory client */
338                );
339
340/***************************************************************************
341Summary:
342        Removes memory client from the jail.
343
344Description:
345        This function is used to remove memory client to the "jail", any specific blocks would
346        be removed from the speocified client.
347        User needs to call function BMRC_Monitor_JailUpdate before changes take effect.
348
349Returns:
350        BERR_SUCCESS - Memory monitor was opened.
351
352See also:
353        BMRC_Monitor_JailUpdate
354        BMRC_Monitor_JailAdd
355****************************************************************************/
356BERR_Code BMRC_Monitor_JailRemove(
357                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
358                BMRC_Monitor_MemoryClientId client /* id of the memory client */
359                );
360
361/***************************************************************************
362Summary:
363        Applies previous JailAdd and JailRemove calls.
364
365Description:
366        This function is used to update memory guards which are used to isolate
367        clients which are set into the "jail" mode.
368
369Returns:
370        BERR_SUCCESS - Memory monitor was opened.
371
372See also:
373        BMRC_Monitor_JailRemove
374        BMRC_Monitor_JailAdd
375****************************************************************************/
376BERR_Code BMRC_Monitor_JailUpdate(
377                BMRC_Monitor_Handle hMonitor /* Instance of the memory monitor */
378                );
379
380
381/***************************************************************************
382Summary:
383        Allow a client to access a memory block.
384
385Description:
386        This works in conjuction with the automatic BMEM configuration.
387        You can change memory clients at runtime instead of modifying
388        bmrc_monitor_clients.c's default list of clients.
389
390        You should user block that was already allocated by the BMEM module,
391        and any number of clients per block.  The actual configuration of memory
392        blocks that will be monitored is based on the capabilities of the
393        ARC hardware.
394
395Returns:
396        BERR_SUCCESS - Memory monitor was opened.
397
398****************************************************************************/
399BERR_Code BMRC_Monitor_BlockTag(
400                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
401                uint32_t ulAddr, /* offset (address) of the allocated block */
402                size_t size,  /* size (in bytes) of the allocated block */
403                BMRC_Monitor_MemoryClientId client /* id of the memory client */
404                );
405
406/***************************************************************************
407Summary:
408        Instead of using the automatic BMEM configuration, manually specify
409        that a client can access a memory block.
410
411Description:
412        This function is used to add a custom memory block instead of using
413        the automatic BMEM configuration.  If you use this, the automatic BMEM
414        configuration is not used. You must configure everything yourself.
415
416        You can add any number of memory blocks, and any number of clients
417        per block.  The actual configuration of memory blocks that will be
418        monitored is based on the capabilities of the ARC hardware.
419
420Note:
421        o Custom memory blocks can not overlap
422        o There is a limited amount of the custom memory block that ould be added
423
424Returns:
425        BERR_SUCCESS - Memory monitor was opened.
426
427See also:
428        BMRC_Monitor_RemoveCustomTag
429
430****************************************************************************/
431BERR_Code BMRC_Monitor_AddCustomTag(
432                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
433                uint32_t ulAddr, /* offset (address) of the memory block */
434                size_t size,  /* size (in bytes) of the memory block */
435                BMRC_Monitor_MemoryClientId client /* id of the memory client */
436                );
437
438/***************************************************************************
439Summary:
440Removes custom block from the memory monitor map
441
442Description:
443This function is used to remove custom memory block.
444Once last custom memory block was removed, memory monitor would use automatic BMEM configuration.
445
446You must call BMRC_Monitor_JailUpdate before this change takes effect.
447
448Returns:
449        BERR_SUCCESS - Memory monitor was opened.
450
451See also:
452        BMRC_Monitor_AddCustomTag
453
454****************************************************************************/
455BERR_Code BMRC_Monitor_RemoveCustomTag(
456                BMRC_Monitor_Handle hMonitor, /* Instance of the memory monitor */
457                uint32_t ulAddr, /* offset (address) of the memory block */
458                size_t size,  /* size (in bytes) of the memory block */
459                BMRC_Monitor_MemoryClientId client /* id of the memory client */
460                );
461
462/***************************************************************************
463Summary:
464Print the names of the clients set in ARC registers.
465
466Description:
467This does a reverse lookup of the ARC client registers. It allows the user
468to see the names of the clients that are currently being monitored.
469
470The client registers are ARC_x_READ_RIGHTS_x and ARC_x_WRITE_RIGHTS_x.
471****************************************************************************/
472BERR_Code BMRC_Monitor_PrintClients(
473        BMRC_Monitor_Handle hMonitor,
474        uint32_t clients0,
475        uint32_t clients1,
476        uint32_t clients2,
477        uint32_t clients3
478        );
479
480#ifdef __cplusplus
481} /* end extern "C" */
482#endif
483
484#endif /* BMRC_MONITOR_H_ */
485
486/* End of File */
487
Note: See TracBrowser for help on using the repository browser.