#error Number of pools out of range (16 Max)!
#endif
-static void gki_add_to_pool_list(UINT8 pool_id);
-static void gki_remove_from_pool_list(UINT8 pool_id);
+#define ALIGN_POOL(pl_size) ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32))
+#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */
+#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */
+#define MAGIC_NO 0xDDBADDBA
+
+#define BUF_STATUS_FREE 0
+#define BUF_STATUS_UNLINKED 1
+#define BUF_STATUS_QUEUED 2
/*******************************************************************************
**
act_size = (UINT16)(tempsize + BUFFER_PADDING_SIZE);
/* Remember pool start and end addresses */
-// btla-specific ++
if(p_mem)
{
p_cb->pool_start[id] = (UINT8 *)p_mem;
p_cb->pool_end[id] = (UINT8 *)p_mem + (act_size * total);
}
-// btla-specific --
p_cb->pool_size[id] = act_size;
p_cb->freeq[id].max_cnt = 0;
/* Initialize index table */
-// btla-specific ++
if(p_mem)
{
hdr = (BUFFER_HDR_T *)p_mem;
hdr1->p_next = NULL;
p_cb->freeq[id]._p_last = hdr1;
}
-// btla-specific --
- return;
}
#if !VALGRIND
tGKI_COM_CB *p_cb = &gki_cb.com;
GKI_TRACE("\ngki_alloc_free_queue in, id:%d \n", (int)id );
- Q = &p_cb->freeq[p_cb->pool_list[id]];
+ Q = &p_cb->freeq[id];
if(Q->_p_first == 0)
{
UINT8 i;
tGKI_COM_CB *p_cb = &gki_cb.com;
- for (i=0; i < p_cb->curr_total_no_of_pools; i++)
+ for (i=0; i < GKI_NUM_FIXED_BUF_POOLS; i++)
{
if ( 0 < p_cb->freeq[i].max_cnt )
{
for (int i = 0; i < GKI_NUM_FIXED_BUF_POOLS; ++i) {
gki_init_free_queue(i, buffer_info[i].size, buffer_info[i].count, NULL);
- p_cb->pool_list[i] = i;
}
-
- p_cb->curr_total_no_of_pools = GKI_NUM_FIXED_BUF_POOLS;
-
- return;
}
-
/*******************************************************************************
**
** Function GKI_init_q
{
p_q->_p_first = p_q->_p_last = NULL;
p_q->_count = 0;
-
- return;
}
-
/*******************************************************************************
**
** Function GKI_getbuf
}
/* Find the first buffer pool that is public that can hold the desired size */
- for (i=0; i < p_cb->curr_total_no_of_pools; i++)
+ for (i=0; i < GKI_NUM_FIXED_BUF_POOLS; i++)
{
- if ( size <= p_cb->freeq[p_cb->pool_list[i]].size )
+ if ( size <= p_cb->freeq[i].size )
break;
}
- if(i == p_cb->curr_total_no_of_pools)
+ if(i == GKI_NUM_FIXED_BUF_POOLS)
{
GKI_exception (GKI_ERROR_BUF_SIZE_TOOBIG, "getbuf: Size is too big");
return (NULL);
/* search the public buffer pools that are big enough to hold the size
* until a free buffer is found */
- for ( ; i < p_cb->curr_total_no_of_pools; i++)
+ for ( ; i < GKI_NUM_FIXED_BUF_POOLS; i++)
{
/* Only look at PUBLIC buffer pools (bypass RESTRICTED pools) */
- if (((UINT16)1 << p_cb->pool_list[i]) & p_cb->pool_access_mask)
+ if (((UINT16)1 << i) & p_cb->pool_access_mask)
continue;
- if ( size <= p_cb->freeq[p_cb->pool_list[i]].size )
- Q = &p_cb->freeq[p_cb->pool_list[i]];
+ if ( size <= p_cb->freeq[i].size )
+ Q = &p_cb->freeq[i];
else
continue;
Q->cur_cnt--;
GKI_enable();
-
- return;
#endif
}
p_hdr->status = BUF_STATUS_QUEUED;
GKI_enable();
-
- return;
}
return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
}
-
/*******************************************************************************
**
** Function GKI_remove_from_queue
return (p_q->_p_first);
}
-
/*******************************************************************************
**
** Function GKI_getlast
return (NULL);
}
-
-
/*******************************************************************************
**
** Function GKI_queue_is_empty
/*******************************************************************************
**
-** Function gki_add_to_pool_list
-**
-** Description Adds pool to the pool list which is arranged in the
-** order of size
-**
-** Returns void
-**
-*******************************************************************************/
-static void gki_add_to_pool_list(UINT8 pool_id)
-{
-
- INT32 i, j;
- tGKI_COM_CB *p_cb = &gki_cb.com;
-
- /* Find the position where the specified pool should be inserted into the list */
- for(i=0; i < p_cb->curr_total_no_of_pools; i++)
- {
-
- if(p_cb->freeq[pool_id].size <= p_cb->freeq[ p_cb->pool_list[i] ].size)
- break;
- }
-
- /* Insert the new buffer pool ID into the list of pools */
- for(j = p_cb->curr_total_no_of_pools; j > i; j--)
- {
- p_cb->pool_list[j] = p_cb->pool_list[j-1];
- }
-
- p_cb->pool_list[i] = pool_id;
-
- return;
-}
-
-/*******************************************************************************
-**
-** Function gki_remove_from_pool_list
-**
-** Description Removes pool from the pool list. Called when a pool is deleted
-**
-** Returns void
-**
-*******************************************************************************/
-static void gki_remove_from_pool_list(UINT8 pool_id)
-{
- tGKI_COM_CB *p_cb = &gki_cb.com;
- UINT8 i;
-
- for(i=0; i < p_cb->curr_total_no_of_pools; i++)
- {
- if(pool_id == p_cb->pool_list[i])
- break;
- }
-
- while (i < (p_cb->curr_total_no_of_pools - 1))
- {
- p_cb->pool_list[i] = p_cb->pool_list[i+1];
- i++;
- }
-
- return;
-}
-
-/*******************************************************************************
-**
-** Function GKI_igetpoolbuf
-**
-** Description Called by an interrupt service routine to get a free buffer from
-** a specific buffer pool.
-**
-** Parameters pool_id - (input) pool ID to get a buffer out of.
-**
-** Returns A pointer to the buffer, or NULL if none available
-**
-*******************************************************************************/
-void *GKI_igetpoolbuf (UINT8 pool_id)
-{
- FREE_QUEUE_T *Q;
- BUFFER_HDR_T *p_hdr;
-
- if (pool_id >= GKI_NUM_TOTAL_BUF_POOLS)
- return (NULL);
-
-
- Q = &gki_cb.com.freeq[pool_id];
- if(Q->cur_cnt < Q->total)
- {
- p_hdr = Q->_p_first;
- Q->_p_first = p_hdr->p_next;
-
- if (!Q->_p_first)
- Q->_p_last = NULL;
-
- if(++Q->cur_cnt > Q->max_cnt)
- Q->max_cnt = Q->cur_cnt;
-
- p_hdr->task_id = GKI_get_taskid();
-
- p_hdr->status = BUF_STATUS_UNLINKED;
- p_hdr->p_next = NULL;
- p_hdr->Type = 0;
-
- return ((void *) ((UINT8 *)p_hdr + BUFFER_HDR_SIZE));
- }
-
- return (NULL);
-}
-
-/*******************************************************************************
-**
** Function GKI_poolcount
**
** Description Called by an application to get the total number of buffers
return ((Q->cur_cnt * 100) / Q->total);
}
-
#include "gki.h"
#include "dyn_mem.h"
-/* Task States: (For OSRdyTbl) */
-#define TASK_DEAD 0 /* b0000 */
-#define TASK_READY 1 /* b0001 */
-#define TASK_WAIT 2 /* b0010 */
-#define TASK_DELAY 4 /* b0100 */
-#define TASK_SUSPEND 8 /* b1000 */
-
+typedef enum {
+ TASK_DEAD,
+ TASK_READY,
+ TASK_WAIT,
+ TASK_DELAY,
+ TASK_SUSPEND,
+} gki_task_state_t;
/********************************************************************
** Internal Error codes
#define GKI_ERROR_GETPOOLBUF_BAD_QID 0xFFF3
#define GKI_ERROR_TIMER_LIST_CORRUPTED 0xFFF2
-
-/********************************************************************
-** Misc constants
-*********************************************************************/
-
-/********************************************************************
-** Buffer Management Data Structures
-*********************************************************************/
-
typedef struct _buffer_hdr
{
struct _buffer_hdr *p_next; /* next buffer in the queue */
UINT16 max_cnt; /* maximum number of buffers allocated at any time */
} FREE_QUEUE_T;
-
-/* Buffer related defines
-*/
-#define ALIGN_POOL(pl_size) ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32))
-#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */
-#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */
-#define MAX_USER_BUF_SIZE ((UINT16)0xffff - BUFFER_PADDING_SIZE) /* pool size must allow for header */
-#define MAGIC_NO 0xDDBADDBA
-
-#define BUF_STATUS_FREE 0
-#define BUF_STATUS_UNLINKED 1
-#define BUF_STATUS_QUEUED 2
-
/* Put all GKI variables into one control block
*/
typedef struct
{
- const char *OSTName[GKI_MAX_TASKS]; /* name of the task */
+ const char *task_name[GKI_MAX_TASKS]; /* name of the task */
+ gki_task_state_t task_state[GKI_MAX_TASKS]; /* current state of the task */
- UINT8 OSRdyTbl[GKI_MAX_TASKS]; /* current state of the task */
UINT16 OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the task */
UINT16 OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/
/* Define the buffer pool access control variables */
UINT16 pool_access_mask; /* Bits are set if the corresponding buffer pool is a restricted pool */
- UINT8 pool_list[GKI_NUM_TOTAL_BUF_POOLS]; /* buffer pools arranged in the order of size */
- UINT8 curr_total_no_of_pools; /* number of fixed buf pools + current number of dynamic pools */
BOOLEAN timer_nesting; /* flag to prevent timer interrupt nesting */
} tGKI_COM_CB;
/* Internal GKI function prototypes
*/
BOOLEAN gki_chk_buf_damage(void *);
-BOOLEAN gki_chk_buf_owner(void *);
void gki_buffer_init (void);
void gki_timers_init(void);
void gki_adjust_timer_count (INT32);
if (gki_cb.com.OSWaitTmr[task_id] <= 0)
{
/* Timer Expired */
- gki_cb.com.OSRdyTbl[task_id] = TASK_READY;
+ gki_cb.com.task_state[task_id] = TASK_READY;
}
}
gki_pthread_info_t *p_pthread_info = (gki_pthread_info_t *)params;
gki_cb.os.thread_id[p_pthread_info->task_id] = pthread_self();
- prctl(PR_SET_NAME, (unsigned long)gki_cb.com.OSTName[p_pthread_info->task_id], 0, 0, 0);
+ prctl(PR_SET_NAME, (unsigned long)gki_cb.com.task_name[p_pthread_info->task_id], 0, 0, 0);
ALOGI("gki_task_entry task_id=%i [%s] starting\n", p_pthread_info->task_id,
- gki_cb.com.OSTName[p_pthread_info->task_id]);
+ gki_cb.com.task_name[p_pthread_info->task_id]);
/* Call the actual thread entry point */
(p_pthread_info->task_entry)(p_pthread_info->params);
ALOGI("gki_task task_id=%i [%s] terminating\n", p_pthread_info->task_id,
- gki_cb.com.OSTName[p_pthread_info->task_id]);
+ gki_cb.com.task_name[p_pthread_info->task_id]);
pthread_exit(0); /* GKI tasks have no return value */
}
return (GKI_FAILURE);
}
- gki_cb.com.OSRdyTbl[task_id] = TASK_READY;
- gki_cb.com.OSTName[task_id] = taskname;
+ gki_cb.com.task_state[task_id] = TASK_READY;
+ gki_cb.com.task_name[task_id] = taskname;
gki_cb.com.OSWaitTmr[task_id] = 0;
gki_cb.com.OSWaitEvt[task_id] = 0;
void GKI_destroy_task(UINT8 task_id)
{
- if (gki_cb.com.OSRdyTbl[task_id] != TASK_DEAD)
+ if (gki_cb.com.task_state[task_id] != TASK_DEAD)
{
- gki_cb.com.OSRdyTbl[task_id] = TASK_DEAD;
+ gki_cb.com.task_state[task_id] = TASK_DEAD;
/* paranoi settings, make sure that we do not execute any mailbox events */
gki_cb.com.OSWaitEvt[task_id] &= ~(TASK_MBOX_0_EVT_MASK|TASK_MBOX_1_EVT_MASK|
ALOGE( "pthread_join() FAILED: result: %d", result );
}
GKI_exit_task(task_id);
- ALOGI( "GKI_shutdown(): task [%s] terminated\n", gki_cb.com.OSTName[task_id]);
+ ALOGI( "GKI_shutdown(): task [%s] terminated\n", gki_cb.com.task_name[task_id]);
}
}
return;
}
- if (gki_cb.com.OSRdyTbl[task_id] != TASK_DEAD)
+ if (gki_cb.com.task_state[task_id] != TASK_DEAD)
{
/* paranoi settings, make sure that we do not execute any mailbox events */
gki_cb.com.OSWaitEvt[task_id] &= ~(TASK_MBOX_0_EVT_MASK|TASK_MBOX_1_EVT_MASK|
* GKI_exception problem due to btu->hci sleep request events */
for (task_id = GKI_MAX_TASKS; task_id > 0; task_id--)
{
- if (gki_cb.com.OSRdyTbl[task_id - 1] != TASK_DEAD)
+ if (gki_cb.com.task_state[task_id - 1] != TASK_DEAD)
{
- gki_cb.com.OSRdyTbl[task_id - 1] = TASK_DEAD;
+ gki_cb.com.task_state[task_id - 1] = TASK_DEAD;
/* paranoi settings, make sure that we do not execute any mailbox events */
gki_cb.com.OSWaitEvt[task_id-1] &= ~(TASK_MBOX_0_EVT_MASK|TASK_MBOX_1_EVT_MASK|
no need to call GKI_disable() here as we know that we will have some events as we've been waking
up after condition pending or timeout */
- if (gki_cb.com.OSRdyTbl[rtask] == TASK_DEAD)
+ if (gki_cb.com.task_state[rtask] == TASK_DEAD)
{
gki_cb.com.OSWaitEvt[rtask] = 0;
/* unlock thread_evt_mutex as pthread_cond_wait() does auto lock when cond is met */
void GKI_delay (UINT32 timeout)
{
- UINT8 rtask = GKI_get_taskid();
struct timespec delay;
int err;
- GKI_TRACE("GKI_delay %d %d", (int)rtask, (int)timeout);
-
delay.tv_sec = timeout / 1000;
- delay.tv_nsec = 1000 * 1000 * (timeout%1000);
+ delay.tv_nsec = 1000 * 1000 * (timeout % 1000);
/* [u]sleep can't be used because it uses SIGALRM */
do {
err = nanosleep(&delay, &delay);
- } while (err < 0 && errno ==EINTR);
-
- /* Check if task was killed while sleeping */
-
- /* NOTE : if you do not implement task killing, you do not need this check */
-
- if (rtask && gki_cb.com.OSRdyTbl[rtask] == TASK_DEAD)
- {
- }
-
- GKI_TRACE("GKI_delay %d %d done", (int)rtask, (int)timeout);
-
- return;
+ } while (err == -1 && errno ==EINTR);
}
-
/*******************************************************************************
**
** Function GKI_send_event
if (task_id == GKI_MAX_TASKS)
task_id = GKI_get_taskid();
- return gki_cb.com.OSTName[task_id];
+ return gki_cb.com.task_name[task_id];
}
/*******************************************************************************
**
*******************************************************************************/
-void GKI_exception (UINT16 code, char *msg)
+void GKI_exception(UINT16 code, char *msg)
{
- UINT8 task_id;
- int i = 0;
-
ALOGE( "GKI_exception(): Task State Table");
- for(task_id = 0; task_id < GKI_MAX_TASKS; task_id++)
+ for (int task_id = 0; task_id < GKI_MAX_TASKS; task_id++)
{
ALOGE( "TASK ID [%d] task name [%s] state [%d]",
task_id,
- gki_cb.com.OSTName[task_id],
- gki_cb.com.OSRdyTbl[task_id]);
+ gki_cb.com.task_name[task_id],
+ gki_cb.com.task_state[task_id]);
}
ALOGE("GKI_exception %d %s", code, msg);
ALOGE( "********************************************************************");
GKI_TRACE("GKI_exception %d %s done", code, msg);
- return;
}
/*******************************************************************************
void GKI_exit_task (UINT8 task_id)
{
GKI_disable();
- gki_cb.com.OSRdyTbl[task_id] = TASK_DEAD;
+ gki_cb.com.task_state[task_id] = TASK_DEAD;
/* Destroy mutex and condition variable objects */
pthread_mutex_destroy(&gki_cb.os.thread_evt_mutex[task_id]);