rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | /* |
| 36 | * Include |
| 37 | */ |
| 38 | |
| 39 | #include "nvram_cache_interface.h" |
| 40 | #include "nvram_cache_info.h" |
| 41 | #include "us_timer.h" |
| 42 | #include "ex_public.h" |
| 43 | |
| 44 | /******************************************************* |
| 45 | * External Function |
| 46 | *******************************************************/ |
| 47 | extern module_type stack_get_active_module_id( void ); |
| 48 | |
| 49 | |
| 50 | /******************************************************* |
| 51 | * Define |
| 52 | *******************************************************/ |
| 53 | |
| 54 | |
| 55 | /******************************************************* |
| 56 | * Typedef |
| 57 | *******************************************************/ |
| 58 | |
| 59 | |
| 60 | /******************************************************* |
| 61 | * Global Variable |
| 62 | *******************************************************/ |
| 63 | nvram_cache_write_queue cache_write_queue; |
| 64 | extern nvram_ee_info_type* nvram_ee_info; |
| 65 | extern kal_char nvram_trace_dump_temp_buffer[]; |
| 66 | extern kal_char nvram_trace_dump_buffer[]; |
| 67 | extern kal_mutexid g_nvram_dump_trace_mutex; |
| 68 | extern kal_wchar nvram_trace_filename[]; |
| 69 | extern FS_HANDLE nvram_trace_file_hdl; |
| 70 | extern kal_uint32 nvram_trace_dump_buffer_offset; |
| 71 | |
| 72 | |
| 73 | /******************************************************* |
| 74 | * Local Function |
| 75 | *******************************************************/ |
| 76 | |
| 77 | |
| 78 | /******************************************************* |
| 79 | * Local Variable |
| 80 | *******************************************************/ |
| 81 | |
| 82 | /***************************************************************************** |
| 83 | * FUNCTION |
| 84 | * nvram_cache_queue_usage_rates |
| 85 | * DESCRIPTION |
| 86 | * get nvram cache queue usage rates |
| 87 | * PARAMETERS |
| 88 | * cache_queue_ldi [OUT] |
| 89 | * RETURNS |
| 90 | * success or fail |
| 91 | *****************************************************************************/ |
| 92 | kal_int32 nvram_cache_queue_usage_rates(void) |
| 93 | { |
| 94 | kal_int32 length = 0; |
| 95 | |
| 96 | length = ((CACHE_QUEUE_SIZE + cache_write_queue.rear - cache_write_queue.front)% CACHE_QUEUE_SIZE); |
| 97 | |
| 98 | return length; |
| 99 | } |
| 100 | |
| 101 | /***************************************************************************** |
| 102 | * FUNCTION |
| 103 | * nvram_cache_queue_full |
| 104 | * DESCRIPTION |
| 105 | * nvram cache queue whether full |
| 106 | * PARAMETERS |
| 107 | * cache_queue_ldi [OUT] |
| 108 | * RETURNS |
| 109 | * success or fail |
| 110 | *****************************************************************************/ |
| 111 | kal_bool nvram_cache_queue_full(void) |
| 112 | { |
| 113 | kal_bool full_flag = KAL_FALSE; |
| 114 | |
| 115 | if((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) { |
| 116 | full_flag = KAL_TRUE; |
| 117 | } |
| 118 | |
| 119 | return full_flag; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | /***************************************************************************** |
| 124 | * FUNCTION |
| 125 | * nvram_cache_queue_empty |
| 126 | * DESCRIPTION |
| 127 | * nvram cache queue whether empty |
| 128 | * PARAMETERS |
| 129 | * cache_queue_ldi [OUT] |
| 130 | * RETURNS |
| 131 | * success or fail |
| 132 | *****************************************************************************/ |
| 133 | kal_bool nvram_cache_queue_empty(void) |
| 134 | { |
| 135 | kal_bool empty_flag = KAL_FALSE; |
| 136 | |
| 137 | if(cache_write_queue.front == cache_write_queue.rear) { |
| 138 | empty_flag = KAL_TRUE; |
| 139 | } |
| 140 | |
| 141 | return empty_flag; |
| 142 | |
| 143 | } |
| 144 | |
| 145 | /***************************************************************************** |
| 146 | * FUNCTION |
| 147 | * nvram_cache_queue_search_lid |
| 148 | * DESCRIPTION |
| 149 | * nvram cache queue whether full |
| 150 | * PARAMETERS |
| 151 | * cache_queue_ldi [OUT] |
| 152 | * RETURNS |
| 153 | * success or fail |
| 154 | *****************************************************************************/ |
| 155 | kal_bool nvram_cache_queue_search_lid(nvram_lid_enum LID) |
| 156 | { |
| 157 | kal_uint16 front; |
| 158 | kal_bool search_flag = KAL_FALSE; |
| 159 | |
| 160 | if(nvram_cache_queue_empty()) { |
| 161 | return KAL_FALSE; |
| 162 | } |
| 163 | |
| 164 | front = cache_write_queue.front; |
| 165 | while(front != cache_write_queue.rear) { |
| 166 | if(cache_write_queue.queue_array[front].ldi->LID == LID) { |
| 167 | search_flag = KAL_TRUE; |
| 168 | break; |
| 169 | } |
| 170 | front = (front+1)%CACHE_QUEUE_SIZE; |
| 171 | } |
| 172 | |
| 173 | return search_flag; |
| 174 | |
| 175 | } |
| 176 | |
| 177 | /***************************************************************************** |
| 178 | * FUNCTION |
| 179 | * nvram_cache_enqueue |
| 180 | * DESCRIPTION |
| 181 | * NVRAM write option push to cache queue |
| 182 | * PARAMETERS |
| 183 | * ldi [IN] |
| 184 | * rec_index [IN] |
| 185 | * rec_amount [IN] |
| 186 | * RETURNS |
| 187 | * success or fail |
| 188 | *****************************************************************************/ |
| 189 | kal_bool nvram_cache_enqueue(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint32 openOption) |
| 190 | { |
| 191 | kal_bool result; |
| 192 | nvram_util_take_mutex(g_nvram_cache_mutex); |
| 193 | if ((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) { |
| 194 | if (!(result = nvram_cache_queue_search_lid(ldi->LID))) { |
| 195 | nvram_util_give_mutex(g_nvram_cache_mutex); |
| 196 | NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_QUEUE_FULL, ldi->LID); |
| 197 | return KAL_FALSE;//assert |
| 198 | }else { |
| 199 | nvram_util_give_mutex(g_nvram_cache_mutex); |
| 200 | return KAL_TRUE; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if (!nvram_cache_queue_search_lid(ldi->LID)) { |
| 205 | |
| 206 | cache_write_queue.queue_array[cache_write_queue.rear].ldi = ldi; |
| 207 | cache_write_queue.queue_array[cache_write_queue.rear].rec_index = rec_index; |
| 208 | cache_write_queue.queue_array[cache_write_queue.rear].rec_amount = rec_amount; |
| 209 | cache_write_queue.queue_array[cache_write_queue.rear].openoption = openOption; |
| 210 | cache_write_queue.rear = (cache_write_queue.rear +1)%CACHE_QUEUE_SIZE; |
| 211 | } |
| 212 | nvram_util_give_mutex(g_nvram_cache_mutex); |
| 213 | return KAL_TRUE; |
| 214 | } |
| 215 | |
| 216 | /***************************************************************************** |
| 217 | * FUNCTION |
| 218 | * nvram_cache_dequeue |
| 219 | * DESCRIPTION |
| 220 | * pop the write option for flsuh data to file |
| 221 | * PARAMETERS |
| 222 | * cache_queue_ldi [OUT] |
| 223 | * RETURNS |
| 224 | * success or fail |
| 225 | *****************************************************************************/ |
| 226 | kal_bool nvram_cache_dequeue(nvram_cache_write_item *cache_queue_ldi) |
| 227 | { |
| 228 | nvram_util_take_mutex(g_nvram_cache_mutex); |
| 229 | if(cache_write_queue.front == cache_write_queue.rear) { |
| 230 | nvram_util_give_mutex(g_nvram_cache_mutex); |
| 231 | return KAL_FALSE; |
| 232 | } |
| 233 | |
| 234 | cache_queue_ldi->ldi = cache_write_queue.queue_array[cache_write_queue.front].ldi; |
| 235 | cache_queue_ldi->rec_index = cache_write_queue.queue_array[cache_write_queue.front].rec_index; |
| 236 | cache_queue_ldi->rec_amount = cache_write_queue.queue_array[cache_write_queue.front].rec_amount; |
| 237 | cache_queue_ldi->openoption = cache_write_queue.queue_array[cache_write_queue.front].openoption; |
| 238 | |
| 239 | cache_write_queue.front = (cache_write_queue.front+1)%CACHE_QUEUE_SIZE; |
| 240 | nvram_util_give_mutex(g_nvram_cache_mutex); |
| 241 | return KAL_TRUE; |
| 242 | } |
| 243 | |
| 244 | /***************************************************************************** |
| 245 | * FUNCTION |
| 246 | * nvram_cache_queue_init |
| 247 | * DESCRIPTION |
| 248 | * nvram cacge queue initialize |
| 249 | * PARAMETERS |
| 250 | * ldi [IN] |
| 251 | * rec_index [IN] |
| 252 | * rec_amount [IN] |
| 253 | * RETURNS |
| 254 | * success or fail |
| 255 | *****************************************************************************/ |
| 256 | kal_bool nvram_cache_queue_init(void) |
| 257 | { |
| 258 | cache_write_queue.front = 0; |
| 259 | cache_write_queue.rear = 0; |
| 260 | cache_write_queue.count = 0; |
| 261 | #if defined (__NVRAM_UT_TEST__) |
| 262 | kal_mem_set(cache_write_queue.queue_array,0,sizeof(cache_write_queue.queue_array[0])*CACHE_QUEUE_SIZE); |
| 263 | #endif |
| 264 | return KAL_TRUE; |
| 265 | } |
| 266 | |