• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 /**
21  * @file mem_req_and_acq.h
22  * @brief Interface for mem request, acquiring and freeing
23  * @author K. J. Nitthilan
24  * @version 1.0
25  * @date 2009-04-21
26  */
27 #ifndef _MEM_REQ_AND_ACQ_H_
28 #define _MEM_REQ_AND_ACQ_H_
29 
30 typedef enum
31 {
32     ALIGN_BYTE = 1,
33     ALIGN_WORD16 = 2,
34     ALIGN_WORD32 = 4,
35     ALIGN_WORD64 = 8,
36     ALIGN_128_BYTE = 128
37 } ITT_MEM_ALIGNMENT_TYPE_E;
38 
39 typedef enum
40 {
41     SCRATCH = 0,
42     PERSISTENT = 1,
43     WRITEONCE = 2
44 } ITT_MEM_USAGE_TYPE_E;
45 
46 typedef enum
47 {
48     L1D = 0,
49     SL2 = 1,
50     DDR = 3
51 } ITT_MEM_REGION_E;
52 
53 typedef enum
54 {
55     GET_NUM_MEMTAB = 0,
56     FILL_MEMTAB = 1,
57     USE_BASE = 2,
58     FILL_BASE = 3
59 } ITT_FUNC_TYPE_E;
60 
61 /*NOTE : This should be an exact replica of IALG_MemRec, any change in IALG_MemRec
62          must be replected here*/
63 typedef struct
64 {
65     UWORD32 u4_size; /* Size in bytes */
66     WORD32 i4_alignment; /* Alignment in bytes */
67     ITT_MEM_REGION_E
68     e_mem_region; /* decides which memory region to be placed */
69     ITT_MEM_USAGE_TYPE_E e_usage; /* memory is scratch or persistent */
70     void *pv_base; /* Base pointer for allocated memory */
71 } itt_memtab_t;
72 
fill_memtab(itt_memtab_t * ps_mem_tab,WORD32 u4_size,WORD32 i4_alignment,ITT_MEM_USAGE_TYPE_E e_usage,ITT_MEM_REGION_E e_mem_region)73 static __inline void fill_memtab(
74     itt_memtab_t *ps_mem_tab,
75     WORD32 u4_size,
76     WORD32 i4_alignment,
77     ITT_MEM_USAGE_TYPE_E e_usage,
78     ITT_MEM_REGION_E e_mem_region)
79 {
80     /* Make the size next multiple of alignment */
81     WORD32 i4_aligned_size = (((u4_size) + (i4_alignment - 1)) & (~(i4_alignment - 1)));
82 
83     /* Fill the memtab */
84     ps_mem_tab->u4_size = i4_aligned_size;
85     ps_mem_tab->i4_alignment = i4_alignment;
86     ps_mem_tab->e_usage = e_usage;
87     ps_mem_tab->e_mem_region = e_mem_region;
88 }
89 
90 static __inline WORD32
use_or_fill_base(itt_memtab_t * ps_mem_tab,void ** ptr_to_be_filled,ITT_FUNC_TYPE_E e_func_type)91     use_or_fill_base(itt_memtab_t *ps_mem_tab, void **ptr_to_be_filled, ITT_FUNC_TYPE_E e_func_type)
92 {
93     /* Fill base for freeing the allocated memory */
94     if(e_func_type == FILL_BASE)
95     {
96         if(ptr_to_be_filled[0] != 0)
97         {
98             ps_mem_tab->pv_base = ptr_to_be_filled[0];
99             return (0);
100         }
101         else
102         {
103             return (-1);
104         }
105     }
106     /* obtain the allocated memory from base pointer */
107     if(e_func_type == USE_BASE)
108     {
109         if(ps_mem_tab->pv_base != 0)
110         {
111             ptr_to_be_filled[0] = ps_mem_tab->pv_base;
112             return (0);
113         }
114         else
115         {
116             return (-1);
117         }
118     }
119     return (0);
120 }
121 
122 #endif /* _MEM_REQ_AND_ACQ_H_*/
123