Home | History | Annotate | Download | only in b_BasicEm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef bbs_MEM_TBL_EM_H
     18 #define bbs_MEM_TBL_EM_H
     19 
     20 /* ---- includes ----------------------------------------------------------- */
     21 
     22 #include "b_BasicEm/MemSeg.h"
     23 
     24 /* ---- related objects  --------------------------------------------------- */
     25 
     26 struct bbs_Context;
     27 
     28 /* ---- typedefs ----------------------------------------------------------- */
     29 
     30 /* ---- constants ---------------------------------------------------------- */
     31 
     32 /* maximum number of exclusive and shared memory segments used, increase this number if needed */
     33 #define bbs_MAX_MEM_SEGS 4
     34 
     35 /* ---- object definition -------------------------------------------------- */
     36 
     37 /** Descriptor of a set of memory segments
     38  *  The first segment in each array (exclusive and shared) with a size > 0 is
     39  *  the default segment.
     40  */
     41 struct bbs_MemTbl
     42 {
     43 	/* number of exclusive memory segments */
     44 	uint32 esSizeE;
     45 
     46 	/** array of exclusive memory segments (for initialisation purposes only ) */
     47 	struct bbs_MemSeg esArrE[ bbs_MAX_MEM_SEGS ];
     48 
     49 	/** array of pointer to exclusive memory segments */
     50 	struct bbs_MemSeg* espArrE[ bbs_MAX_MEM_SEGS ];
     51 
     52 	/* number of shared memory segments */
     53 	uint32 ssSizeE;
     54 
     55 	/** array of shared memory segments */
     56 	struct bbs_MemSeg ssArrE[ bbs_MAX_MEM_SEGS ];
     57 };
     58 
     59 /* ---- associated objects ------------------------------------------------- */
     60 
     61 /* ---- external functions ------------------------------------------------- */
     62 
     63 /* ---- \ghd{ constructor/destructor } ------------------------------------- */
     64 
     65 /** initializes bbs_MemTbl  */
     66 void bbs_MemTbl_init( struct bbs_Context* cpA,
     67 					  struct bbs_MemTbl* ptrA );
     68 
     69 /** resets bbs_MemTbl  */
     70 void bbs_MemTbl_exit( struct bbs_Context* cpA,
     71 					  struct bbs_MemTbl* ptrA );
     72 
     73 /* ---- \ghd{ operators } -------------------------------------------------- */
     74 
     75 /* ---- \ghd{ query functions } -------------------------------------------- */
     76 
     77 /* indicates whether memory segment overalps with any segment in memory table */
     78 flag bbs_MemTbl_overlap( struct bbs_Context* cpA,
     79 						 struct bbs_MemTbl* ptrA,
     80 						 const void* memPtrA, uint32 sizeA );
     81 
     82 /* ---- \ghd{ modify functions } ------------------------------------------- */
     83 
     84 /* ---- \ghd{ memory I/O } ------------------------------------------------- */
     85 
     86 /* ---- \ghd{ exec functions } --------------------------------------------- */
     87 
     88 /** creates a memory table with one exclusive and one shared segment from a coherent memory block */
     89 void bbs_MemTbl_create( struct bbs_Context* cpA,
     90 					    struct bbs_MemTbl* ptrA,
     91 						void* memPtrA,
     92 						uint32 sizeA,
     93 						uint32 sharedSubSizeA );
     94 
     95 /** adds new exclusive segment to table ( default segment must be added first ) */
     96 void bbs_MemTbl_add( struct bbs_Context* cpA,
     97 					 struct bbs_MemTbl* ptrA,
     98 					 void* memPtrA,
     99 					 uint32 sizeA,
    100 					 uint32 idA );
    101 
    102 /** adds new shared segment to table ( default segment must be added first )  */
    103 void bbs_MemTbl_addShared( struct bbs_Context* cpA,
    104 						   struct bbs_MemTbl* ptrA,
    105 						   void* memPtrA,
    106 						   uint32 sizeA,
    107 						   uint32 idA );
    108 
    109 /** returns specified segment. If specified segment is not found the default segment is returned */
    110 struct bbs_MemSeg* bbs_MemTbl_segPtr( struct bbs_Context* cpA,
    111 									  struct bbs_MemTbl* ptrA,
    112 									  uint32 idA );
    113 
    114 struct bbs_MemSeg* bbs_MemTbl_sharedSegPtr( struct bbs_Context* cpA,
    115 										    struct bbs_MemTbl* ptrA,
    116 											uint32 idA );
    117 
    118 /* Search functions below are obsolete. Please use bbs_MemTbl_segPtr or bbs_MemTbl_sharedSegPtr instead. */
    119 
    120 /** returns pointer to fastest exclusive segment that has at least minSizeA words available */
    121 struct bbs_MemSeg* bbs_MemTbl_fastestSegPtr( struct bbs_Context* cpA,
    122 											 struct bbs_MemTbl* ptrA,
    123 											 uint32 minSizeA );
    124 
    125 /** returns pointer to exclusive segment that has most words available */
    126 struct bbs_MemSeg* bbs_MemTbl_largestSegPtr( struct bbs_Context* cpA,
    127 											 struct bbs_MemTbl* ptrA );
    128 
    129 /** returns fastest shared segment that has at least minSizeA words available */
    130 struct bbs_MemSeg* bbs_MemTbl_fastestSharedSegPtr( struct bbs_Context* cpA,
    131 												   struct bbs_MemTbl* ptrA,
    132 												   uint32 minSizeA );
    133 
    134 /** returns shared segment that has most words available */
    135 struct bbs_MemSeg* bbs_MemTbl_largestSharedSegPtr( struct bbs_Context* cpA,
    136 												   struct bbs_MemTbl* ptrA );
    137 
    138 #endif /* bbs_MEM_TBL_EM_H */
    139 
    140