source: svn/newcon3bcm2_21bu/magnum/basemodules/mem/bmem.h @ 43

Last change on this file since 43 was 43, checked in by megakiss, 11 years ago

광주방송 OTC 주파수 369Mhz로 변경

  • Property svn:executable set to *
File size: 34.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2001-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: bmem.h $
11 * $brcm_Revision: Hydra_Software_Devel/30 $
12 * $brcm_Date: 8/24/11 5:35p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/mem/bmem.h $
19 *
20 * Hydra_Software_Devel/30   8/24/11 5:35p albertl
21 * SW7405-5349:  Added line parameter to memory monitor interface.
22 *
23 * Hydra_Software_Devel/28   8/23/11 3:33p albertl
24 * SW7405-5349: Added line parameter to memory monitor interface.
25 *
26 * Hydra_Software_Devel/27   1/10/11 3:31p albertl
27 * SW7408-193: BMEM_Heapinfo now includes high watermark.  Added
28 * BMEM_Heap_ResetHighWatermark().
29 *
30 * Hydra_Software_Devel/26   4/8/10 1:34p erickson
31 * SW7550-370: specify units for all alignment params
32 *
33 * Hydra_Software_Devel/25   2/25/10 5:01p albertl
34 * SW7325-655: Added BMEM_Heap_FreeCached.
35 *
36 * Hydra_Software_Devel/24   12/3/08 5:17p albertl
37 * PR48035: Added ulTotalFree and ulTotalAllocated to BMEM_HeapInfo.
38 *
39 * Hydra_Software_Devel/23   10/24/08 5:43p albertl
40 * PR48199, PR48046: Removed BMEM_SetCache entirely as it is obsolete.
41 *
42 * Hydra_Software_Devel/22   6/16/06 3:22p albertl
43 * PR20247, PR20276, PR20354:  Added the ability to control debug
44 * configuration at runtime.  Added address and offset checking to
45 * conversion functions.  BMEM_SetCache can now only be called before
46 * heaps are allocated from.  Added BMEM_Heap functions.
47 *
48 * Hydra_Software_Devel/21   2/8/06 7:29p hongtaoz
49 * PR19082: BMEM_Alloc returns NULL pointer if size is zero;
50 *
51 * Hydra_Software_Devel/20   10/7/05 3:53p jasonh
52 * PR 17374: Allowed GetHeapInfo to return original creation parameters.
53 *
54 * Hydra_Software_Devel/19   3/10/05 5:05p albertl
55 * PR13677:  Both local and system bookkeeping made available at heap
56 * creation though functions BMEM_CreateHeapSystem and
57 * BMEM_CreateHeapLocal.
58 *
59 * Hydra_Software_Devel/18   11/2/04 5:27p pntruong
60 * PR13076: Added cached memory support for rul.
61 *
62 * Hydra_Software_Devel/17   11/2/04 10:32a hongtaoz
63 * PR13076: added cached memory support;
64 *
65 * Hydra_Software_Devel/16   10/8/04 3:27p yuxiaz
66 * PR9076: Change isr functions to _isr.
67 *
68 * Hydra_Software_Devel/15   4/9/04 12:48p vsilyaev
69 * PR 10201: Changed description for the memory monitor interface
70 *
71 * Hydra_Software_Devel/14   4/1/04 12:49p vsilyaev
72 * PR 10201: Added memory monitor
73 *
74 * Hydra_Software_Devel/13   2/25/04 2:52p hongtaoz
75 * PR9855: removed redundent functions BMEM_Report and BMEM_ReportVerbose;
76 * being aware of that BMEM_Dbg_DumpBlock and BMEM_Dbg_DumpHeap suffice
77 * heap debug requirement; avoid using floating point in BMEM_Dbg_Map;
78 *
79 * Hydra_Software_Devel/12   12/31/03 1:02p jasonh
80 * PR 8796: Added documentation to clarify cached/uncached memory.
81 *
82 * Hydra_Software_Devel/11   12/31/03 12:02p jasonh
83 * PR 8940: Changed return type of destroyheap to void. Removed use of
84 * DEBUG macro and printf.
85 *
86 * Hydra_Software_Devel/10   10/6/03 11:39a jasonh
87 * Documentation update to clarify creation arguments.
88 *
89 * Hydra_Software_Devel/9   9/15/03 5:19p jasonh
90 * Fixed offset argument. Changed report functions to return void.
91 *
92 * Hydra_Software_Devel/8   9/5/03 2:48p jasonh
93 * Added documentation for function arguments.
94 *
95 * Hydra_Software_Devel/7   9/5/03 2:01p jasonh
96 * Added documentation. Added GetHeapInfo and GetLargestAvailableBlockSize
97 * prototypes.
98 *
99 * Hydra_Software_Devel/6   9/2/03 1:52p vadim
100 * Conforms to magnum.
101 *
102 * Hydra_Software_Devel/3   3/21/03 6:04p erickson
103 * edited comments
104 *
105 * Hydra_Software_Devel/2   3/20/03 3:51p erickson
106 * renamed all MEM_ to BMEM_
107 *
108 * Hydra_Software_Devel/1   3/20/03 3:24p erickson
109 * initial bmem work, taken from SetTop/memorylib
110 ***************************************************************************/
111#ifndef BMEM_H__
112#define BMEM_H__
113
114#ifdef __cplusplus
115extern "C" {
116#endif
117
118#include "bmem_config.h"
119
120/*=Module Overview: ********************************************************
121The purpose of this module is to provide functions and controls for the
122management of memory heaps. Users are allowed to create heaps, allocate
123from those heaps, free memory back to the heap, and convert betweeen
124device offsets and software addresses.
125
126In addition, this module contains several controls which may be configured
127at compile time. These features allow you to customize the implementation
128of the memory manager to your specific needs.
129
130Configuration Controls
131----------------------
132
133o BMEM_SAFETY_CONFIG - overall policy the memory manager will follow.
134o BMEM_BOOKKEEPING_CONFIG - location of bookkeeping information.
135o BMEM_REENTRANT_CONFIG - determine whether the memory manager operates
136                          in a reentrant manner.
137
138See Also:
139        BMEM_Heap_Create,
140        BMEM_SAFETY_CONFIG,
141        BMEM_BOOKKEEPING_CONFIG,
142        BMEM_REENTRANT_CONFIG
143****************************************************************************/
144
145/* main MEM module handle */
146typedef struct BMEM_P_Mem *BMEM_ModuleHandle;
147
148/***************************************************************************
149Summary:
150        A handle representing one heap of the memory manager.
151
152Description:
153        Memory described by this heap is considered to be device memory. Memory
154        contained within this heap can then be used by additional modules to
155        contain frame buffers, surfaces, or any other memory that needs to be
156        provided directly to the hardware.
157
158See Also:
159        BMEM_Heap_Create,
160****************************************************************************/
161typedef struct BMEM_P_Heap *BMEM_Heap_Handle;
162
163typedef enum BMEM_SafetyConfig
164{
165    BMEM_SafetyConfig_eFastest = BMEM_CONFIG_FASTEST,
166    BMEM_SafetyConfig_eNormal  = BMEM_CONFIG_NORMAL,
167    BMEM_SafetyConfig_eTrack   = BMEM_CONFIG_TRACK,
168    BMEM_SafetyConfig_eSafe    = BMEM_CONFIG_SAFE,
169    BMEM_SafetyConfig_eSafest  = BMEM_CONFIG_SAFEST
170} BMEM_SafetyConfig;
171
172
173typedef enum BMEM_Bookkeeping
174{
175    BMEM_BookKeeping_eLocal  = BMEM_BOOKKEEPING_LOCAL,
176    BMEM_BookKeeping_eSystem = BMEM_BOOKKEEPING_SYSTEM
177} BMEM_BookKeeping;
178
179
180/***************************************************************************
181Description:
182        Callback called to flush the cache.
183        Its implementation is platform-specific.
184
185See Also:
186        BMEM_Heap_InstallMonitor
187****************************************************************************/
188typedef void (*BMEM_FlushCallback)( const void *pvCachedAddress, size_t size );
189
190
191/***************************************************************************
192Summary:
193        Holds interesting information about the heap.
194
195Description:
196        This is the public structure used to hold information about a heap. This
197        information can be retrieved with the BMEM_Heap_GetInfo function.
198
199See Also:
200        BMEM_Heap_GetInfo
201****************************************************************************/
202typedef struct BMEM_HeapInfo
203{
204        void         *pvAddress;            /* Start address of the heap. */
205        uint32_t      ulOffset;             /* Device offset of the heap. */
206        size_t        zSize;                /* Size of the heap in bytes. */
207        unsigned int  uiAlignment;          /* Heap alignment (power of 2). */
208
209        size_t        ulLargestFree;        /* Size of the largest free block
210                                               in bytes */
211        size_t        ulSmallestFree;       /* Size of the smallest free block
212                                               in bytes */
213        size_t        ulTotalFree;          /* Total free memory in heap.  This
214                                                                                   is the combined size of all free
215                                                                                   blocks.  Just because a certain
216                                                                                   amount of memory is free does not
217                                                                                   mean that amount can be allocated.
218                                                                                   Allocated memory must still fit
219                                                                                   within a block, but this provides
220                                                                                   information on the overall usage of
221                                                                                   memory in a system. */
222        unsigned int  ulNumFree;            /* Number of free blocks */
223        size_t        ulLargestAllocated;   /* Size of the largest allocated
224                                               block in bytes */
225        size_t        ulSmallestAllocated;  /* Size of the smallest allocated
226                                               block in bytes */
227        size_t        ulTotalAllocated;     /* Total allocated memory in heap */
228        size_t        ulHighWatermark;      /* Most memory used at one time */
229        unsigned int  ulNumAllocated;       /* Number of allocated blocks */
230        unsigned int  ulNumErrors;          /* Number of errors detected in
231                                               the heap since creation */
232
233} BMEM_HeapInfo;
234
235
236/* default settings for module (currently empty) */
237typedef void * BMEM_Settings;
238
239
240/***************************************************************************
241Summary:
242        Settings structure for heap creation.
243
244Description:
245        This is the public structure used to configure a heap upon
246        its creation.
247
248        Alignment is used to specify the minimum alignment of all block
249        allocations within the heap, and is specified as a power of 2,
250        measured in bytes in device offset space. Thus, 0 is unaligned,
251        1 is 2-byte aligned, 2 is 4-byte aliged, 16 is 64K-aligned, 24
252        is 16MB-aligned, etc.
253
254See Also:
255        BMEM_Heap_Create
256****************************************************************************/
257typedef struct BMEM_Heap_Settings
258{
259    unsigned int        uiAlignment;    /* enforced byte alignment on allocated memory (default 0) (power of 2 units) */
260
261    BMEM_SafetyConfig   eSafetyConfig;  /* safety configuration for this heap (default: compile flag) */
262    BMEM_BookKeeping    eBookKeeping;   /* bookkeeping configuration for this heap (default: compile flag) */
263
264    void               *pCachedAddress; /* default: 0 (if flush is NULL then this value is not used) */
265    BMEM_FlushCallback  flush;          /* Callback used to flush cache at task time (default: NULL) */
266    BMEM_FlushCallback  flush_isr;      /* Callback used to flush cache at isr time (default: NULL) */
267
268} BMEM_Heap_Settings;
269
270
271/***************************************************************************
272Summary:
273        Fills in a BMEM_Settings structure with default settings.
274
275Description:
276
277Returns:
278        BERR_SUCCESS - Default settings obtained.
279
280See Also:
281****************************************************************************/
282BERR_Code BMEM_GetDefaultSettings
283(
284        BMEM_Settings *pDefSettings
285);
286
287/***************************************************************************
288Summary:
289        Opens the MEM module.
290
291Description:
292
293Returns:
294        BERR_SUCCESS - MEM module successfully opened.
295
296See Also:
297****************************************************************************/
298BERR_Code BMEM_Open
299(
300    BMEM_ModuleHandle   *phMem,
301    const BMEM_Settings *pDefSettings
302);
303
304/***************************************************************************
305Summary:
306        Closes the MEM module.
307
308Description:
309
310Returns:
311        BERR_SUCCESS - MEM module successfully closed.
312
313See Also:
314****************************************************************************/
315void BMEM_Close
316(
317    BMEM_ModuleHandle hMem
318);
319
320/***************************************************************************
321Summary:
322        Fills in a BMEM_Heap_Settings structure with default settings.
323
324Description:
325
326Returns:
327        BERR_SUCCESS - Default settings obtained.
328
329See Also:
330****************************************************************************/
331BERR_Code BMEM_Heap_GetDefaultSettings
332(
333    BMEM_Heap_Settings *pHeapSettings
334);
335
336/***************************************************************************
337Summary:
338        Creates a memory heap.
339
340Description:
341        The arguments given to this function describe where the heap is
342        located for software and hardware usage, the size of the heap, and
343        additional configuration settings for the heap.
344
345        Configuration settings include alignment restrictions placed on
346        allocated blocks, local or system bookeeping, the safety configuration,
347        in additional to cache settings.
348
349        In order to create a heap, you must first determine where the
350        physical memory has been mapped by the OS. This mapping allows
351        you to provide the mapped location of the heap accessible
352        by software (pvAddress) along with the starting physical
353        address of the memory that is being mapped (ulOffset). This
354        address range must correspond to a contiguous device address
355        range.
356
357        Heaps provided to other software modules must refer to
358        uncached address space unless a module's documentation states
359        otherwise.
360
361        For example, if you had 64 megabytes in the system, and wanted
362        to map the last 16 megabytes to software address 0xF0000000 to
363        0xF1000000, you would create a heap where pvAddress = 0xF0000000,
364        ulOffset = 0x03000000 (48 megabyte offset), and
365        zSize = 0x01000000 (16 megabyte heap).
366
367        When blocks are allocated from the heap, the mapped software
368        address will always be returned. If that block address needs to be
369        provided to a hardware register, it can be converted by using
370        the function BMEM_ConvertAddressToOffset. To go back to a
371        mapped software address, use BMEM_ConvertOffsetToAddress.
372
373        For example, using the previously created heap, If I allocated
374        a block from the heap, I would get a returned block address
375        ranging from 0xF0000000 to 0xF1000000. If I got a block address
376        of 0xF0000000 and then converted it to offset, I would get
377        the value 0x03000000. Converting an offset of 0x03000000 to
378        an address would return 0xF0000000.
379
380Returns:
381        BERR_SUCCESS - Heap was created.
382
383See Also:
384        BMEM_Heap_Destroy,
385        BMEM_Heap_Validate,
386        BMEM_Heap_Report,
387        BMEM_Heap_ReportVerbose,
388        BMEM_Heap_Alloc,
389        BMEM_Heap_AllocAligned,
390        BMEM_Heap_Free,
391        BMEM_Heap_ConvertOffsetToAddress,
392        BMEM_Heap_ConvertAddressToOffset,
393        BMEM_Heap_GetLargestAvailableBlockSize,
394        BMEM_Heap_GetInfo
395****************************************************************************/
396BERR_Code BMEM_Heap_Create
397(
398    BMEM_ModuleHandle   hMem,          /* main handle from BMEM_Open() - NULL is possible for older chipsets (7038/3560 only) */
399    void               *pvAddress,     /* Pointer to beginning of memory chunk to manage (uncached) */
400    uint32_t            ulOffset,      /* Device offset of initial location */
401    size_t              zSize,         /* Size of chunk to manage in bytes */
402    BMEM_Heap_Settings *pHeapSettings, /* default settings */
403    BMEM_Heap_Handle   *phHeap         /* returned heap */
404);
405
406/***************************************************************************
407Summary:
408        Destroys the provided heap.
409
410Description:
411        Heaps are destroyed by calling BMEM_Heap_Destroy. This normally only
412        happens when the system is being shut down.
413
414        If the heap is not empty (contains allocations), then
415        BERR_LEAKED_RESOURCE is returned and the heap is not destroyed.
416
417See Also:
418        BMEM_Heap_Create
419****************************************************************************/
420void BMEM_Heap_Destroy
421(
422        BMEM_Heap_Handle Heap   /* Heap to destroy. */
423);
424
425/***************************************************************************
426Summary:
427        Checks heap for errors.
428
429Description:
430        When debug features are enabled, such as guard banding, this routine
431        checks all allocated blocks to insure that they are still valid.
432
433Returns:
434        BERR_SUCCESS - Heap was valid.
435
436See Also:
437        BMEM_SAFETY_CONFIG
438****************************************************************************/
439BERR_Code BMEM_Heap_Validate
440(
441        BMEM_Heap_Handle Heap  /* Heap to validate. */
442);
443
444/*{private}*****************************************************************
445Summary:
446        Private allocation function.
447
448Description:
449        This is the main workhorse allocation function. The allocation
450        functions BMEM_Alloc and BMEM_AllocAligned are implemented as macros
451        around this function. This function implements features for those
452        functions while also allowing the file and line number to be tagged
453        to the allocated memory (for debugging purposes).
454
455        Tagging can be enabled or disabled by setting BMEM_SAFETY_CONFIG
456        appropriately.
457
458        This function should never be called directly. Its arguments may
459        change over time when new methods of allocation are made available.
460
461Returns:
462        Pointer to allocated address or NULL on failure.
463
464See Also:
465        BMEM_Heap_Alloc,
466        BMEM_Heap_AllocAligned,
467        BMEM_SAFETY_CONFIG
468****************************************************************************/
469void *BMEM_P_Heap_TagAllocAligned
470(
471        BMEM_Heap_Handle  pheap,       /* Heap to allocate from */
472        size_t            ulSize,      /* size in bytes of block to allocate */
473        unsigned int      uiAlignment, /* alignment for the block (power of 2) */
474        unsigned int      Boundary,    /* boundry restricting allocated value */
475        const char*       pchFile,     /* source filename where block is
476                                                                  allocated from */
477        int               iLine        /* line number in file where allocation
478                                                                  occurs */
479);
480
481/***************************************************************************
482Summary:
483        Allocates memory from a heap.
484
485Description:
486        Returns a software address to an allocated piece of memory. Allocated
487        memory will use the Heap's native alignment and contain no Boundary
488        restrictions.
489
490        Equivalent to calling BMEM_Heap_AllocAligned(Heap, Size, 0, 0).
491
492Input:
493        Heap - Heap to allocate from.
494        Size - The number of bytes to allocate.
495
496        Note, if the size is zero, will return NULL pointer.
497
498Returns:
499        Pointer to allocated address or NULL on failure.
500
501See Also:
502        BMEM_Heap_AllocAligned
503****************************************************************************/
504#define BMEM_Heap_Alloc(Heap, Size) \
505        BMEM_P_Heap_TagAllocAligned(Heap, Size, 0, 0, __FILE__, __LINE__)
506
507/***************************************************************************
508Summary:
509        Allocates memory from a heap.
510
511Description:
512        This function is similar to BMEM_Heap_Alloc except that it allows the
513        user additional Alignment and Boundary controls.
514
515        Alignment is used to specify the required alignment and is specified
516        as a power of 2, measured in bytes in device offset space. Thus, 0 is
517        unaligned, 1 is 2-byte aligned, 2 is 4-byte aliged, 16 is 64K-aligned,
518        24 is 16MB-aligned, etc.
519
520        If the Alignment value is less than the Heap alignement (provided to
521        BMEM_HeapCreate) then the Heap's alignment will be used.
522
523        Boundary specifies a boundary that an allocation must not cross in
524        device offset space. This is measured in the same way as Alignment.
525        A value of zero specifies no boundary. This value must not correspond
526        to a size smaller than AllocationSize.
527
528Input:
529        Heap - Heap to allocate from.
530        Size - The number of bytes to allocate.
531        Alignment - Required alignment of the returned memory (power of 2).
532        Boundary - Prevents allocations across this boundry.
533
534Returns:
535        Pointer to allocated address or NULL on failure.
536
537See Also:
538        BMEM_Heap_Alloc
539****************************************************************************/
540#define BMEM_Heap_AllocAligned(Heap, Size, Alignment, Boundry) \
541        BMEM_P_Heap_TagAllocAligned(Heap, Size, Alignment, Boundry, \
542                __FILE__, __LINE__)
543
544/***************************************************************************
545Summary:
546        Free memory allocated from heap.
547
548Description:
549        Any memory allocated with a call to BMEM_Heap_Alloc or
550        BMEM_Heap_AllocAligned may be returned to the heap by calling this
551        function. Attempting to free a pointer which was not allocated with
552        those functions may cause errors in future allocations.
553
554        If the supplied address is NULL, it is ignored and the function
555        will successfully return.
556
557        After the block has been freed, it is coalesced with any adjacent free
558        blocks in order to maximize the size of free regions in the heap.
559
560Returns:
561        BERR_SUCCESS - Memory was returned to the heap.
562
563See Also:
564        BMEM_Heap_FreeCached,
565        BMEM_Heap_Alloc,
566        BMEM_Heap_AllocAligned
567****************************************************************************/
568BERR_Code BMEM_Heap_Free
569(
570        BMEM_Heap_Handle  Heap,     /* Heap from which the block was allocated. */
571        void             *Address   /* Allocated block address. */
572);
573
574/***************************************************************************
575Summary:
576        Free cached memory allocated from heap.
577
578Description:
579        This function flushes allocated cached memory then frees it.
580
581        If the supplied address is NULL, it will return an error code.
582
583        After the block has been freed, it is coalesced with any adjacent free
584        blocks in order to maximize the size of free regions in the heap.
585
586Returns:
587        BERR_SUCCESS - Memory was returned to the heap.
588        BERR_INVALID_PARAMETER - Heap address or cached address was invalid.
589
590See Also:
591        BMEM_Heap_Free,
592        BMEM_Heap_Alloc,
593        BMEM_Heap_AllocAligned
594****************************************************************************/
595BERR_Code BMEM_Heap_FreeCached
596(
597        BMEM_Heap_Handle  Heap,           /* Heap from which the block was allocated. */
598        void             *CachedAddress   /* Allocated cached block address. */
599);
600
601/***************************************************************************
602Summary:
603        Converts device offset to address.
604
605Description:
606        This function must only be called for regions allocated through
607        BMEM_Heap_Alloc or BMEM_Heap_AllocAligned. If other addresses are
608        provided, this function may return BERR_INVALID_PARAMETER.
609
610Returns:
611        BERR_SUCCESS - Conversion was successful.
612        BERR_INVALID_PARAMETER - Offset was invalid for this heap.
613
614See Also:
615        BMEM_Heap_ConvertOffsetToAddress
616****************************************************************************/
617BERR_Code BMEM_Heap_ConvertOffsetToAddress
618(
619        BMEM_Heap_Handle   Heap,      /* Heap that contains the memory block */
620        uint32_t           ulOffset,  /* Device offset within the heap. */
621        void             **ppvAddress /* [out] Returned address. */
622);
623
624/***************************************************************************
625Summary:
626        Converts address to device offset.
627
628Description:
629        This function must only be called for regions allocated through
630        BMEM_Heap_Alloc or BMEM_Heap_AllocAligned. If other addresses are
631        provided, this function may return BERR_INVALID_PARAMETER.
632
633Returns:
634        BERR_SUCCESS - Conversion was successful.
635        BERR_INVALID_PARAMETER - Address was invalid for this heap.
636
637See Also:
638        BMEM_Heap_ConvertOffsetToAddress
639****************************************************************************/
640BERR_Code BMEM_Heap_ConvertAddressToOffset
641(
642        BMEM_Heap_Handle  Heap,      /* Heap that contains the memory block. */
643        void             *pvAddress, /* Address of the memory block */
644        uint32_t         *pulOffset  /* [out] Returned device offset. */
645);
646
647/***************************************************************************
648Summary:
649        Converts address to device offset at isr.
650
651Description:
652        This function must only be called for regions allocated through
653        BMEM_Heap_Alloc or BMEM_Heap_AllocAligned. If other addresses are
654        provided, this function may return BERR_INVALID_PARAMETER.
655
656Returns:
657        BERR_SUCCESS - Conversion was successful.
658        BERR_INVALID_PARAMETER - Address was invalid for this heap.
659
660See Also:
661        BMEM_Heap_ConvertOffsetToAddress
662****************************************************************************/
663#define BMEM_Heap_ConvertAddressToOffset_isr(Heap, pvAddress, pulOffset) \
664        BMEM_Heap_ConvertAddressToOffset(Heap, pvAddress, pulOffset)
665
666
667/***************************************************************************
668Summary:
669        Gets the largest size block which can be successfully be allocated.
670
671Description:
672        This function assumes that the allocated block will be aligned to the
673        heap alignment and have no boundry restrictions.
674
675Returns:
676        Maximum size of a block (in bytes) which can be allocated.
677****************************************************************************/
678size_t BMEM_Heap_GetLargestAvailableBlockSize(
679        BMEM_Heap_Handle  pheap           /* Heap to check */
680);
681
682/***************************************************************************
683Summary:
684        Gets information about the heap.
685
686Description:
687        This function fills in a structure with a variety of interesting
688        information about the heap. This information is mainly useful for
689        debugging and statistic gathering. See the BMEM_Heap_HeapInfo structure
690        definition for the set of information returned.
691
692Returns:
693        Maximum size of a block (in bytes) which can be allocated.
694
695See Also:
696        BMEM_Heap_ResetHighWatermark
697****************************************************************************/
698void BMEM_Heap_GetInfo
699(
700        BMEM_Heap_Handle pheap,   /* Heap to get information from. */
701        BMEM_HeapInfo      *phi   /* [out] Returned information. */
702);
703
704/***************************************************************************
705Summary:
706        Resets high memory watermark tracked by the heap.
707
708Description:
709        The heap tracks the high memory watermark (the most amount of memory
710        used at one time) when BMEM_Heap_GetInfo() is called.  This function
711        resets that value back to zero so it can track a new maximum.
712
713See Also:
714        BMEM_Heap_GetInfo
715****************************************************************************/
716void BMEM_Heap_ResetHighWatermark
717(
718        BMEM_Heap_Handle pheap
719);
720
721/***************************************************************************
722Description:
723This structure is used to describe interface used to monitor memory  allocations and deallocations in a heap. This interface provides
724alloc and free hooks which will be called after when block is allocated or freed from the heap.
725Single interface could be used to monitor several heaps.
726
727****************************************************************************/
728typedef struct BMEM_MonitorInterface
729{
730        void *cnxt; /*  User specified context */
731        void (*alloc)(void *cnxt, uint32_t addr, size_t size, const char *fname, int line); /* callback function called when new block was allocated */
732        void (*free)(void *cnxt, uint32_t addr); /* callback function called when block was deallocated */
733} BMEM_MonitorInterface;
734
735/***************************************************************************
736Summary:
737        Install monitor to control memory allocation;
738
739Description:
740        This function is used to install application defined monitor to control for the memory allocation.
741        This is application responsibility to keep monitor valid until it's removed or memory heap destroyed.
742
743Returns:
744        BERR_SUCCESS - Monitor was installed
745
746
747See Also:
748        BMEM_MonitorInterface
749        BMEM_Heap_RemoveMonitor
750****************************************************************************/
751BERR_Code BMEM_Heap_InstallMonitor(BMEM_Heap_Handle heap, BMEM_MonitorInterface *monitor);
752
753/***************************************************************************
754Summary:
755        Removes memory allocation monitor.
756
757Description:
758        This function is used to remove application defined monitor.
759
760Returns:
761        N/A
762
763See Also:
764        BMEM_Heap_InstallMonitor
765****************************************************************************/
766void BMEM_Heap_RemoveMonitor(BMEM_Heap_Handle heap, BMEM_MonitorInterface *monitor);
767
768/***************************************************************************
769Summary:
770        Converts software address to cached memory address.
771
772Description:
773        This function is used to take pointer from BMEM_Heap_Alloc or BMEM_Heap_AllocAligned
774        and turn into cached address. If other addresses are used, it may return
775        BERR_INVALID_PARAMETER.
776
777Returns:
778        BERR_SUCCESS - Conversion was successful.
779
780See Also:
781        BMEM_Heap_FlushCache
782        BMEM_Heap_FlushCache_isr
783****************************************************************************/
784/*  */
785BERR_Code BMEM_Heap_ConvertAddressToCached
786(
787   BMEM_Heap_Handle  Heap,             /* Heap that contains the memory block. */
788   void            *pvAddress,        /* Address of the memory block */
789   void           **ppvCachedAddress  /* [out] Returned cache address. */
790);
791
792/***************************************************************************
793Summary:
794        Converts software address to cached memory address.
795
796Description:
797        The isr version of BMEM_Heap_ConvertAddressToCached.
798
799Returns:
800        BERR_SUCCESS - Conversion was successful.
801
802See Also:
803        BMEM_Heap_ConvertAddressToCached
804****************************************************************************/
805#define BMEM_Heap_ConvertAddressToCached_isr(Heap, pvAddress, ppvCachedAddress) \
806        BMEM_Heap_ConvertAddressToCached(Heap, pvAddress, ppvCachedAddress)
807
808/***************************************************************************
809Summary:
810        Flush cached data to the device memory, or read back data from memory to
811        cache.
812
813Description:
814        This routine will be required if and only if the user is accessing memory
815        through a cached address. If you are modifying cached memory, you must
816        call BMEM_Heap_FluchCache before the memory can be passed to hardware.
817        If you are reading from cached memory that was written by hardware, you
818        must also call BMEM_Heap_Flush_Cache on the memory required.
819
820Returns:
821        BERR_SUCCESS - flushn was successful.
822
823See Also:
824        BMEM_Heap_FlushCache_isr
825****************************************************************************/
826BERR_Code BMEM_Heap_FlushCache
827(
828   BMEM_Heap_Handle  Heap,             /* Heap containing the cached memory. */
829   void             *pvCachedAddress,  /* Start address to flush */
830   size_t            size              /* Size in bytes of the block to flush */
831);
832
833/***************************************************************************
834Summary:
835        The isr version of BMEM_Heap_FlushCache.
836
837Description:
838        The difference between these two routines is that the isr routine will
839        call the isr callback (cb_isr) and the non-isr routine will call the non-isr
840        callback (cb). In both cases, if the function pointer is NULL (hasn't been
841        set) this function will return without error. This represents a function
842        calling BMEM_Heap_FlushCache without cache parameters enabled.
843
844Returns:
845        BERR_SUCCESS - flushn was successful.
846
847See Also:
848        BMEM_Heap_FlushCache
849****************************************************************************/
850BERR_Code BMEM_Heap_FlushCache_isr
851(
852   BMEM_Heap_Handle  Heap,             /* Heap containing the cached memory. */
853   void             *pvCachedAddress,  /* Start address to flush */
854   size_t            size              /* Size in bytes of the block to flush */
855);
856
857
858/***************************************************************************
859   For backwards compatibility
860 ****************************************************************************/
861
862typedef BMEM_Heap_Handle BMEM_Handle;
863
864/***************************************************************************
865Summary:
866        Creates a memory heap.
867
868Description:
869        The arguments given to this function describe where the heap is
870        located for software and hardware usage, the size of the heap,
871        and any restrictions to alignment placed upon allocated blocks
872        returned from the heap.
873
874Returns:
875        BERR_SUCCESS - Heap was created.
876
877See Also:
878        BMEM_DestroyHeap,
879        BMEM_ValidateHeap,
880        BMEM_Report,
881        BMEM_ReportVerbose,
882        BMEM_Alloc,
883        BMEM_AllocAligned,
884        BMEM_Free,
885        BMEM_ConvertOffsetToAddress,
886        BMEM_ConvertAddressToOffset,
887        BMEM_GetLargestAvailableBlockSize,
888        BMEM_GetHeapInfo
889****************************************************************************/
890BERR_Code BMEM_CreateHeap
891(
892        BMEM_Handle *ppHeap,      /* Heap to be created. */
893        void        *pvAddress,   /* Start address of the heap. */
894        uint32_t     ulOffset,    /* Device offset of the heap. */
895        size_t       zSize,       /* Size of the heap in bytes. */
896        unsigned int uiAlignment  /* Heap alignment (power of 2). */
897);
898
899/**********************************************************************func*
900 * BMEM_CreateHeapSystem - Initializes the heap with system bookkeeping.
901 *
902 * This function inititalizes a heap at a given location and size.
903 * Any previous allocations in the chunk of memory handed over to this
904 * function are lost. Every heap has a base minimum alignment for all of
905 * the allocations within that heap. (However, you can specify a greater
906 * alignment when actually doing an allocation.)
907 *
908 * In this implementation, memory in the CPU's system heap is used to store
909 * the bookkeeping information for the heap.
910 *
911 * Returns:
912 *   Returns true if heap is initialized, or false if the size of the heap
913 *   is too small to manage or there isn't enough system memory to allocate
914 *   bookkeeping information.
915 *
916 */
917BERR_Code BMEM_CreateHeapSystem
918(
919        BMEM_Handle *ppHeap,      /* Heap to be created. */
920        void        *pvAddress,   /* Start address of the heap. */
921        uint32_t     ulOffset,    /* Device offset of the heap. */
922        size_t       zSize,       /* Size of the heap in bytes. */
923        unsigned int uiAlignment  /* Heap alignment (power of 2). */
924);
925
926/**********************************************************************func*
927 * BMEM_CreateHeapLocal - Initializes the heap with local bookkeeping.
928 *
929 * This function inititalizes a heap at a given location and size.
930 * Any previous allocations in the chunk of memory handed over to this
931 * function are lost. Every heap has a base minimum alignment for all of
932 * the allocations within that heap. (However, you can specify a greater
933 * alignment when actually doing an allocation.)
934 *
935 * In this implementation, the first bit of the heap is used to store heap
936 * information such as pointers to the free and used list, as well as other
937 * bookkeeping information.
938 *
939 * Returns:
940 *   Returns true if heap is initialized, or false if the given memory
941 *   chunk is too small to be a heap.
942 *
943 */
944BERR_Code BMEM_CreateHeapLocal
945(
946        BMEM_Handle *ppHeap,      /* Heap to be created. */
947        void        *pvAddress,   /* Start address of the heap. */
948        uint32_t     ulOffset,    /* Device offset of the heap. */
949        size_t       zSize,       /* Size of the heap in bytes. */
950        unsigned int uiAlignment  /* Heap alignment (power of 2). */
951);
952
953#define BMEM_DestroyHeap BMEM_Heap_Destroy
954#define BMEM_ValidateHeap BMEM_Heap_Validate
955#define BMEM_Alloc BMEM_Heap_Alloc
956#define BMEM_AllocAligned BMEM_Heap_AllocAligned
957#define BMEM_Free BMEM_Heap_Free
958#define BMEM_ConvertOffsetToAddress BMEM_Heap_ConvertOffsetToAddress
959#define BMEM_ConvertAddressToOffset BMEM_Heap_ConvertAddressToOffset
960#define BMEM_ConvertAddressToOffset_isr BMEM_Heap_ConvertAddressToOffset_isr
961#define BMEM_GetLargestAvailableBlockSize BMEM_Heap_GetLargestAvailableBlockSize
962#define BMEM_GetHeapInfo BMEM_Heap_GetInfo
963#define BMEM_InstallMonitor BMEM_Heap_InstallMonitor
964#define BMEM_RemoveMonitor BMEM_Heap_RemoveMonitor
965#define BMEM_ConvertAddressToCached BMEM_Heap_ConvertAddressToCached
966#define BMEM_ConvertAddressToCached_isr BMEM_Heap_ConvertAddressToCached_isr
967#define BMEM_FlushCache BMEM_Heap_FlushCache
968#define BMEM_FlushCache_isr BMEM_Heap_FlushCache_isr
969
970#ifdef __cplusplus
971} /* end extern "C" */
972#endif
973
974#endif /* #ifndef BMEM_H__ */
975
976/* End of File */
Note: See TracBrowser for help on using the repository browser.