| /***************************************************************************** |
| * Copyright Statement: |
| * -------------------- |
| * This software is protected by Copyright and the information contained |
| * herein is confidential. The software may not be copied and the information |
| * contained herein may not be used or disclosed except with the written |
| * permission of MediaTek Inc. (C) 2005 |
| * |
| * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| * |
| * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| * |
| * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| * |
| *****************************************************************************/ |
| /* |
| * Include |
| */ |
| |
| #include "nvram_cache_interface.h" |
| #include "nvram_cache_info.h" |
| #include "us_timer.h" |
| #include "ex_public.h" |
| |
| /******************************************************* |
| * External Function |
| *******************************************************/ |
| extern module_type stack_get_active_module_id( void ); |
| |
| |
| /******************************************************* |
| * Define |
| *******************************************************/ |
| |
| |
| /******************************************************* |
| * Typedef |
| *******************************************************/ |
| |
| |
| /******************************************************* |
| * Global Variable |
| *******************************************************/ |
| nvram_cache_write_queue cache_write_queue; |
| extern nvram_ee_info_type* nvram_ee_info; |
| extern kal_char nvram_trace_dump_temp_buffer[]; |
| extern kal_char nvram_trace_dump_buffer[]; |
| extern kal_mutexid g_nvram_dump_trace_mutex; |
| extern kal_wchar nvram_trace_filename[]; |
| extern FS_HANDLE nvram_trace_file_hdl; |
| extern kal_uint32 nvram_trace_dump_buffer_offset; |
| |
| |
| /******************************************************* |
| * Local Function |
| *******************************************************/ |
| |
| |
| /******************************************************* |
| * Local Variable |
| *******************************************************/ |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_queue_usage_rates |
| * DESCRIPTION |
| * get nvram cache queue usage rates |
| * PARAMETERS |
| * cache_queue_ldi [OUT] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_int32 nvram_cache_queue_usage_rates(void) |
| { |
| kal_int32 length = 0; |
| |
| length = ((CACHE_QUEUE_SIZE + cache_write_queue.rear - cache_write_queue.front)% CACHE_QUEUE_SIZE); |
| |
| return length; |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_queue_full |
| * DESCRIPTION |
| * nvram cache queue whether full |
| * PARAMETERS |
| * cache_queue_ldi [OUT] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_queue_full(void) |
| { |
| kal_bool full_flag = KAL_FALSE; |
| |
| if((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) { |
| full_flag = KAL_TRUE; |
| } |
| |
| return full_flag; |
| |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_queue_empty |
| * DESCRIPTION |
| * nvram cache queue whether empty |
| * PARAMETERS |
| * cache_queue_ldi [OUT] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_queue_empty(void) |
| { |
| kal_bool empty_flag = KAL_FALSE; |
| |
| if(cache_write_queue.front == cache_write_queue.rear) { |
| empty_flag = KAL_TRUE; |
| } |
| |
| return empty_flag; |
| |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_queue_search_lid |
| * DESCRIPTION |
| * nvram cache queue whether full |
| * PARAMETERS |
| * cache_queue_ldi [OUT] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_queue_search_lid(nvram_lid_enum LID) |
| { |
| kal_uint16 front; |
| kal_bool search_flag = KAL_FALSE; |
| |
| if(nvram_cache_queue_empty()) { |
| return KAL_FALSE; |
| } |
| |
| front = cache_write_queue.front; |
| while(front != cache_write_queue.rear) { |
| if(cache_write_queue.queue_array[front].ldi->LID == LID) { |
| search_flag = KAL_TRUE; |
| break; |
| } |
| front = (front+1)%CACHE_QUEUE_SIZE; |
| } |
| |
| return search_flag; |
| |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_enqueue |
| * DESCRIPTION |
| * NVRAM write option push to cache queue |
| * PARAMETERS |
| * ldi [IN] |
| * rec_index [IN] |
| * rec_amount [IN] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_enqueue(nvram_ltable_entry_struct* ldi, kal_uint16 rec_index, kal_uint16 rec_amount, kal_uint32 openOption) |
| { |
| kal_bool result; |
| nvram_util_take_mutex(g_nvram_cache_mutex); |
| if ((cache_write_queue.rear +1)%CACHE_QUEUE_SIZE == cache_write_queue.front) { |
| if (!(result = nvram_cache_queue_search_lid(ldi->LID))) { |
| nvram_util_give_mutex(g_nvram_cache_mutex); |
| NVRAM_EXT_ASSERT(KAL_FALSE, (kal_uint32)result, NVRAM_ERROR_LOC_NVCACHE_ERRNO_QUEUE_FULL, ldi->LID); |
| return KAL_FALSE;//assert |
| }else { |
| nvram_util_give_mutex(g_nvram_cache_mutex); |
| return KAL_TRUE; |
| } |
| } |
| |
| if (!nvram_cache_queue_search_lid(ldi->LID)) { |
| |
| cache_write_queue.queue_array[cache_write_queue.rear].ldi = ldi; |
| cache_write_queue.queue_array[cache_write_queue.rear].rec_index = rec_index; |
| cache_write_queue.queue_array[cache_write_queue.rear].rec_amount = rec_amount; |
| cache_write_queue.queue_array[cache_write_queue.rear].openoption = openOption; |
| cache_write_queue.rear = (cache_write_queue.rear +1)%CACHE_QUEUE_SIZE; |
| } |
| nvram_util_give_mutex(g_nvram_cache_mutex); |
| return KAL_TRUE; |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_dequeue |
| * DESCRIPTION |
| * pop the write option for flsuh data to file |
| * PARAMETERS |
| * cache_queue_ldi [OUT] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_dequeue(nvram_cache_write_item *cache_queue_ldi) |
| { |
| nvram_util_take_mutex(g_nvram_cache_mutex); |
| if(cache_write_queue.front == cache_write_queue.rear) { |
| nvram_util_give_mutex(g_nvram_cache_mutex); |
| return KAL_FALSE; |
| } |
| |
| cache_queue_ldi->ldi = cache_write_queue.queue_array[cache_write_queue.front].ldi; |
| cache_queue_ldi->rec_index = cache_write_queue.queue_array[cache_write_queue.front].rec_index; |
| cache_queue_ldi->rec_amount = cache_write_queue.queue_array[cache_write_queue.front].rec_amount; |
| cache_queue_ldi->openoption = cache_write_queue.queue_array[cache_write_queue.front].openoption; |
| |
| cache_write_queue.front = (cache_write_queue.front+1)%CACHE_QUEUE_SIZE; |
| nvram_util_give_mutex(g_nvram_cache_mutex); |
| return KAL_TRUE; |
| } |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_cache_queue_init |
| * DESCRIPTION |
| * nvram cacge queue initialize |
| * PARAMETERS |
| * ldi [IN] |
| * rec_index [IN] |
| * rec_amount [IN] |
| * RETURNS |
| * success or fail |
| *****************************************************************************/ |
| kal_bool nvram_cache_queue_init(void) |
| { |
| cache_write_queue.front = 0; |
| cache_write_queue.rear = 0; |
| cache_write_queue.count = 0; |
| #if defined (__NVRAM_UT_TEST__) |
| kal_mem_set(cache_write_queue.queue_array,0,sizeof(cache_write_queue.queue_array[0])*CACHE_QUEUE_SIZE); |
| #endif |
| return KAL_TRUE; |
| } |
| |