Commit 1a3844f9 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Scott James Remnant
Browse files

GKI cleanup - Replaced usage of GKI queue with OSI fixed_queue

* Added new functions to OSI:
  - fixed_queue_init()
  - fixed_queue_length()
  - fixed_queue_try_remove_from_queue()
  - fixed_queue_try_peek_last()

* Renamed fixed_queue_try_peek() to fixed_queue_try_peek_first()

* Replaced usage of GKI queue functions with OSI fixed_queue functions:
  - GKI_init_q() -> fixed_queue_new(SIZE_MAX)
    NOTE: unlike GKI_init_q(), fixed_queue_new() allocates memory /
    state that needs to be released by calling fixed_queue_free()
  - GKI_enqueue() -> fixed_queue_enqueue()
  - GKI_dequeue() -> fixed_queue_try_dequeue()
    NOTE: fixed_queue_try_dequeue() is non-blocking
  - GKI_queue_length() -> fixed_queue_length()
  - GKI_queue_is_empty() -> fixed_queue_is_empty()
  - GKI_getfirst() -> fixed_queue_try_peek_first()
  - GKI_getlast() -> fixed_queue_try_peek_last()
  - GKI_remove_from_queue() -> fixed_queue_try_remove_from_queue()
  - Queue elements iteration.
    In the fixed_queue implementation we have to use the underlying
    list_t mechanism to iterate over the elements.
    OLD:
      p = GKI_getfirst(queue);
      ...
      while ((p = GKI_getnext(p) != NULL) {
         ...
      }
    NEW:
      list_t *list = fixed_queue_get_list(queue);
      for (const list_node_t *node = list_begin(list);
           node != list_end(list); node = list_next(node)) {
          p = list_node(node);
      }

* Remove initialization of the GKI module, because it is not needed
  anymore

* Removed unused files in GKI:
  gki/common/gki_common.h
  gki/ulinux/gki_int.h
  gki/ulinux/gki_ulinux.c

Change-Id: I3ff9464db75252d6faf7476a9ca67c88e535c51c
parent 1eb1ea0c
......@@ -96,7 +96,6 @@ LOCAL_C_INCLUDES+= . \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../btcore/include \
$(LOCAL_PATH)/../gki/common \
$(LOCAL_PATH)/../gki/ulinux \
$(LOCAL_PATH)/../hci/include \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../stack/include \
......
......@@ -101,7 +101,6 @@ static_library("bta") {
"//",
"//btcore/include",
"//gki/common",
"//gki/ulinux",
"//hci/include",
"//include",
"//stack/include",
......
......@@ -1039,9 +1039,9 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
/* clean up cache */
if(p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache)
{
while (!GKI_queue_is_empty(&p_clcb->p_srcb->cache_buffer))
while (! fixed_queue_is_empty(p_clcb->p_srcb->cache_buffer))
{
GKI_freebuf (GKI_dequeue (&p_clcb->p_srcb->cache_buffer));
GKI_freebuf(fixed_queue_try_dequeue(p_clcb->p_srcb->cache_buffer));
}
p_clcb->p_srcb->p_srvc_cache = NULL;
}
......@@ -1908,8 +1908,8 @@ void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
/* in all other cases, mark it and delete the cache */
if (p_srvc_cb->p_srvc_cache != NULL)
{
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer))
GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
while (! fixed_queue_is_empty(p_srvc_cb->cache_buffer))
GKI_freebuf(fixed_queue_try_dequeue(p_srvc_cb->cache_buffer));
p_srvc_cb->p_srvc_cache = NULL;
}
......
......@@ -155,7 +155,7 @@ BT_HDR *bta_gattc_alloc_cache_buf(tBTA_GATTC_SERV *p_srvc_cb)
p_srvc_cb->free_byte = GKI_get_buf_size(p_buf);
/* link into buffer queue */
GKI_enqueue(&p_srvc_cb->cache_buffer, p_buf);
fixed_queue_enqueue(p_srvc_cb->cache_buffer, p_buf);
}
#if BTA_GATT_DEBUG== TRUE
APPL_TRACE_DEBUG("allocating new buffer: free byte = %d", p_srvc_cb->free_byte);
......@@ -175,8 +175,12 @@ tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb)
{
tBTA_GATT_STATUS status = BTA_GATT_OK;
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer))
GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
if (p_srvc_cb->cache_buffer != NULL) {
while (! fixed_queue_is_empty(p_srvc_cb->cache_buffer))
GKI_freebuf(fixed_queue_try_dequeue(p_srvc_cb->cache_buffer));
} else {
p_srvc_cb->cache_buffer = fixed_queue_new(SIZE_MAX);
}
utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
......@@ -1497,8 +1501,8 @@ void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srvc_cb, UINT16 num_attr,
APPL_TRACE_ERROR("bta_gattc_rebuild_cache");
if (attr_index == 0)
{
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer))
GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
while (! fixed_queue_is_empty(p_srvc_cb->cache_buffer))
GKI_freebuf(fixed_queue_try_dequeue(p_srvc_cb->cache_buffer));
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL)
{
......
......@@ -25,6 +25,8 @@
#define BTA_GATTC_INT_H
#include "bt_target.h"
#include "osi/include/fixed_queue.h"
#include "bta_sys.h"
#include "bta_gatt_api.h"
#include "bta_gattc_ci.h"
......@@ -321,7 +323,7 @@ typedef struct
tBTA_GATTC_CACHE *p_srvc_cache;
tBTA_GATTC_CACHE *p_cur_srvc;
BUFFER_Q cache_buffer; /* buffer queue used for storing the cache data */
fixed_queue_t *cache_buffer; /* buffer queue used for storing the cache data */
UINT8 *p_free; /* starting point to next available byte */
UINT16 free_byte; /* number of available bytes in server cache buffer */
UINT8 update_count; /* indication received */
......
......@@ -413,11 +413,15 @@ tBTA_GATTC_SERV * bta_gattc_srcb_alloc(BD_ADDR bda)
if (p_tcb != NULL)
{
while (!GKI_queue_is_empty(&p_tcb->cache_buffer))
GKI_freebuf (GKI_dequeue (&p_tcb->cache_buffer));
if (p_tcb->cache_buffer != NULL) {
while (! fixed_queue_is_empty(p_tcb->cache_buffer))
GKI_freebuf(fixed_queue_try_dequeue(p_tcb->cache_buffer));
fixed_queue_free(p_tcb->cache_buffer, NULL);
}
utl_freebuf((void **)&p_tcb->p_srvc_list);
memset(p_tcb, 0 , sizeof(tBTA_GATTC_SERV));
p_tcb->cache_buffer = fixed_queue_new(SIZE_MAX);
p_tcb->in_use = TRUE;
bdcpy(p_tcb->server_bda, bda);
......
......@@ -116,7 +116,7 @@ static void bta_pan_conn_state_cback(UINT16 handle, BD_ADDR bd_addr, tPAN_RESULT
p_scb->peer_role = dst_role;
p_scb->pan_flow_enable = TRUE;
bdcpy(p_scb->bd_addr, bd_addr);
GKI_init_q(&p_scb->data_queue);
p_scb->data_queue = fixed_queue_new(SIZE_MAX);
if(src_role == PAN_ROLE_CLIENT)
p_scb->app_id = bta_pan_cb.app_id[0];
......@@ -241,7 +241,7 @@ static void bta_pan_data_buf_ind_cback(UINT16 handle, BD_ADDR src, BD_ADDR dst,
return;
}
GKI_enqueue(&p_scb->data_queue, p_new_buf);
fixed_queue_enqueue(p_scb->data_queue, p_new_buf);
if ((p_event = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
p_event->layer_specific = handle;
......@@ -486,7 +486,7 @@ void bta_pan_disable(void)
{
if (p_scb->in_use)
{
while((p_buf = (BT_HDR *)GKI_dequeue(&p_scb->data_queue)) != NULL)
while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_scb->data_queue)) != NULL)
GKI_freebuf(p_buf);
bta_pan_co_close(p_scb->handle, p_scb->app_id);
......@@ -650,11 +650,9 @@ void bta_pan_conn_close(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
bta_sys_conn_close( BTA_ID_PAN ,p_scb->app_id, p_scb->bd_addr);
/* free all queued up data buffers */
while((p_buf = (BT_HDR *)GKI_dequeue(&p_scb->data_queue)) != NULL)
while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_scb->data_queue)) != NULL)
GKI_freebuf(p_buf);
GKI_init_q(&p_scb->data_queue);
bta_pan_scb_dealloc(p_scb);
bta_pan_cb.p_cback(BTA_PAN_CLOSE_EVT, (tBTA_PAN *)&data);
......@@ -719,8 +717,8 @@ void bta_pan_tx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
bta_pan_co_tx_path(p_scb->handle, p_scb->app_id);
/* free data that exceeds queue level */
while(GKI_queue_length(&p_scb->data_queue) > bta_pan_cb.q_level)
GKI_freebuf(GKI_dequeue(&p_scb->data_queue));
while (fixed_queue_length(p_scb->data_queue) > bta_pan_cb.q_level)
GKI_freebuf(fixed_queue_try_dequeue(p_scb->data_queue));
bta_pan_pm_conn_idle(p_scb);
}
/* if configured for zero copy push */
......@@ -730,7 +728,7 @@ void bta_pan_tx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
if (p_scb->app_flow_enable == TRUE)
{
/* read data from the queue */
if ((p_buf = (BT_HDR *)GKI_dequeue(&p_scb->data_queue)) != NULL)
if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_scb->data_queue)) != NULL)
{
/* send data to application */
bta_pan_co_tx_writebuf(p_scb->handle,
......@@ -744,12 +742,12 @@ void bta_pan_tx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
}
/* free data that exceeds queue level */
while(GKI_queue_length(&p_scb->data_queue) > bta_pan_cb.q_level)
GKI_freebuf(GKI_dequeue(&p_scb->data_queue));
while (fixed_queue_length(p_scb->data_queue) > bta_pan_cb.q_level)
GKI_freebuf(fixed_queue_try_dequeue(p_scb->data_queue));
/* if there is more data to be passed to
upper layer */
if(!GKI_queue_is_empty(&p_scb->data_queue))
if (!fixed_queue_is_empty(p_scb->data_queue))
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
......
......@@ -203,9 +203,8 @@ BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16* p_p
p_scb = bta_pan_scb_by_handle(handle);
p_buf = (BT_HDR *)GKI_dequeue(&p_scb->data_queue);
if(p_buf)
p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_scb->data_queue);
if (p_buf != NULL)
{
bdcpy(src,((tBTA_PAN_DATA_PARAMS *)p_buf)->src);
bdcpy(dst,((tBTA_PAN_DATA_PARAMS *)p_buf)->dst);
......
......@@ -24,6 +24,7 @@
#ifndef BTA_PAN_INT_H
#define BTA_PAN_INT_H
#include "osi/include/fixed_queue.h"
#include "bta_sys.h"
#include "bta_pan_api.h"
......@@ -138,7 +139,7 @@ typedef union
typedef struct
{
BD_ADDR bd_addr; /* peer bdaddr */
BUFFER_Q data_queue; /* Queue of buffers waiting to be passed to application */
fixed_queue_t *data_queue; /* Queue of buffers waiting to be passed to application */
UINT16 handle; /* BTA PAN/BNEP handle */
BOOLEAN in_use; /* scb in use */
tBTA_SEC sec_mask; /* Security mask */
......
......@@ -304,6 +304,7 @@ static void bta_pan_api_open(tBTA_PAN_DATA *p_data)
void bta_pan_scb_dealloc(tBTA_PAN_SCB *p_scb)
{
APPL_TRACE_DEBUG("bta_pan_scb_dealloc %d", bta_pan_scb_to_idx(p_scb));
fixed_queue_free(p_scb->data_queue, NULL);
memset(p_scb, 0, sizeof(tBTA_PAN_SCB));
}
......
......@@ -205,6 +205,7 @@ void bta_sys_init(void)
void bta_sys_free(void) {
fixed_queue_free(btu_bta_alarm_queue, NULL);
btu_bta_alarm_queue = NULL;
hash_map_free(bta_alarm_hash_map);
pthread_mutex_destroy(&bta_alarm_lock);
}
......
......@@ -216,8 +216,8 @@ typedef union
typedef struct
{
#if (BTA_AV_INCLUDED == TRUE)
BUFFER_Q TxAaQ;
BUFFER_Q RxSbcQ;
fixed_queue_t *TxAaQ;
fixed_queue_t *RxSbcQ;
BOOLEAN is_tx_timer;
BOOLEAN is_rx_timer;
UINT16 TxAaMtuSize;
......@@ -270,7 +270,7 @@ extern OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context
OI_UINT8 pcmStride,
OI_BOOL enhanced);
#endif
static void btif_media_flush_q(BUFFER_Q *p_q);
static void btif_media_flush_q(fixed_queue_t *p_q);
static void btif_media_task_aa_handle_stop_decoding(void );
static void btif_media_task_aa_rx_flush(void);
......@@ -328,7 +328,7 @@ static void log_tstamps_us(char *comment)
static UINT64 prev_us = 0;
const UINT64 now_us = time_now_us();
APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d", comment, now_us, now_us - prev_us,
GKI_queue_length(&btif_media_cb.TxAaQ));
fixed_queue_length(btif_media_cb.TxAaQ));
prev_us = now_us;
}
......@@ -755,11 +755,10 @@ void btif_a2dp_stop_media_task(void)
// Exit thread
fixed_queue_free(btif_media_cmd_msg_queue, NULL);
btif_media_cmd_msg_queue = NULL;
thread_post(worker_thread, btif_media_thread_cleanup, NULL);
thread_free(worker_thread);
worker_thread = NULL;
btif_media_cmd_msg_queue = NULL;
}
/*****************************************************************************
......@@ -1094,13 +1093,11 @@ void btif_a2dp_set_tx_flush(BOOLEAN enable)
#if (BTA_AV_SINK_INCLUDED == TRUE)
static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
{
UINT8 count;
tBT_SBC_HDR *p_msg;
int num_sbc_frames;
int num_frames_to_process;
count = btif_media_cb.RxSbcQ._count;
if (0 == count)
if (fixed_queue_is_empty(btif_media_cb.RxSbcQ))
{
APPL_TRACE_DEBUG(" QUE EMPTY ");
}
......@@ -1108,7 +1105,7 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
{
if (btif_media_cb.rx_flush == TRUE)
{
btif_media_flush_q(&(btif_media_cb.RxSbcQ));
btif_media_flush_q(btif_media_cb.RxSbcQ);
return;
}
......@@ -1117,13 +1114,14 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
do
{
p_msg = (tBT_SBC_HDR *)GKI_getfirst(&(btif_media_cb.RxSbcQ));
p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btif_media_cb.RxSbcQ);
if (p_msg == NULL)
return;
num_sbc_frames = p_msg->num_frames_to_be_processed; /* num of frames in Que Packets */
APPL_TRACE_DEBUG(" Frames left in topmost packet %d", num_sbc_frames);
APPL_TRACE_DEBUG(" Remaining frames to process in tick %d", num_frames_to_process);
APPL_TRACE_DEBUG(" Num of Packets in Que %d", btif_media_cb.RxSbcQ._count);
APPL_TRACE_DEBUG(" Num of Packets in Que %d",
fixed_queue_length(btif_media_cb.RxSbcQ));
if ( num_sbc_frames > num_frames_to_process) /* Que Packet has more frames*/
{
......@@ -1136,7 +1134,7 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context)
else /* Que packet has less frames */
{
btif_media_task_handle_inc_media(p_msg);
p_msg = (tBT_SBC_HDR *)GKI_dequeue(&(btif_media_cb.RxSbcQ));
p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btif_media_cb.RxSbcQ);
if( p_msg == NULL )
{
APPL_TRACE_ERROR("Insufficient data in que ");
......@@ -1187,6 +1185,8 @@ static void btif_media_thread_init(UNUSED_ATTR void *context) {
UIPC_Init(NULL);
#if (BTA_AV_INCLUDED == TRUE)
btif_media_cb.TxAaQ = fixed_queue_new(SIZE_MAX);
btif_media_cb.RxSbcQ = fixed_queue_new(SIZE_MAX);
UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb);
#endif
......@@ -1201,6 +1201,11 @@ static void btif_media_thread_cleanup(UNUSED_ATTR void *context) {
/* this calls blocks until uipc is fully closed */
UIPC_Close(UIPC_CH_ID_ALL);
#if (BTA_AV_INCLUDED == TRUE)
fixed_queue_free(btif_media_cb.TxAaQ, NULL);
fixed_queue_free(btif_media_cb.RxSbcQ, NULL);
#endif
/* Clear media task flag */
media_task_running = MEDIA_TASK_STATE_OFF;
}
......@@ -1237,11 +1242,11 @@ BOOLEAN btif_media_task_send_cmd_evt(UINT16 Evt)
** Returns void
**
*******************************************************************************/
static void btif_media_flush_q(BUFFER_Q *p_q)
static void btif_media_flush_q(fixed_queue_t *p_q)
{
while (!GKI_queue_is_empty(p_q))
while (! fixed_queue_is_empty(p_q))
{
GKI_freebuf(GKI_dequeue(p_q));
GKI_freebuf(fixed_queue_try_dequeue(p_q));
}
}
......@@ -1494,7 +1499,7 @@ BOOLEAN btif_media_task_aa_rx_flush_req(void)
{
BT_HDR *p_buf;
if (GKI_queue_is_empty(&(btif_media_cb.RxSbcQ))== TRUE) /* Que is already empty */
if (fixed_queue_is_empty(btif_media_cb.RxSbcQ)) /* Que is already empty */
return TRUE;
if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
......@@ -1555,7 +1560,7 @@ static void btif_media_task_aa_rx_flush(void)
/* Flush all enqueued GKI SBC buffers (encoded) */
APPL_TRACE_DEBUG("btif_media_task_aa_rx_flush");
btif_media_flush_q(&(btif_media_cb.RxSbcQ));
btif_media_flush_q(btif_media_cb.RxSbcQ);
}
......@@ -1578,7 +1583,7 @@ static void btif_media_task_aa_tx_flush(BT_HDR *p_msg)
btif_media_cb.media_feeding_state.pcm.counter = 0;
btif_media_cb.media_feeding_state.pcm.aa_feed_residue = 0;
btif_media_flush_q(&(btif_media_cb.TxAaQ));
btif_media_flush_q(btif_media_cb.TxAaQ);
UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, NULL);
}
......@@ -2281,11 +2286,11 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
{
tBT_SBC_HDR *p_msg;
if(btif_media_cb.rx_flush == TRUE) /* Flush enabled, do not enque*/
return GKI_queue_length(&btif_media_cb.RxSbcQ);
if(GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
if (btif_media_cb.rx_flush == TRUE) /* Flush enabled, do not enque */
return fixed_queue_length(btif_media_cb.RxSbcQ);
if (fixed_queue_length(btif_media_cb.RxSbcQ) == MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
{
GKI_freebuf(GKI_dequeue(&(btif_media_cb.RxSbcQ)));
GKI_freebuf(fixed_queue_try_dequeue(btif_media_cb.RxSbcQ));
}
BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf + ");
......@@ -2296,8 +2301,8 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len));
p_msg->num_frames_to_be_processed = (*((UINT8*)(p_msg + 1) + p_msg->offset)) & 0x0f;
BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf + ", p_msg->num_frames_to_be_processed);
GKI_enqueue(&(btif_media_cb.RxSbcQ), p_msg);
if(GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_A2DP_DELAYED_START_FRAME_COUNT)
fixed_queue_enqueue(btif_media_cb.RxSbcQ, p_msg);
if (fixed_queue_length(btif_media_cb.RxSbcQ) == MAX_A2DP_DELAYED_START_FRAME_COUNT)
{
BTIF_TRACE_DEBUG(" Initiate Decoding ");
btif_media_task_aa_handle_start_decoding();
......@@ -2308,7 +2313,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
/* let caller deal with a failed allocation */
BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf No Buffer left - ");
}
return GKI_queue_length(&btif_media_cb.RxSbcQ);
return fixed_queue_length(btif_media_cb.RxSbcQ);
}
/*******************************************************************************
......@@ -2322,7 +2327,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
*******************************************************************************/
BT_HDR *btif_media_aa_readbuf(void)
{
return GKI_dequeue(&(btif_media_cb.TxAaQ));
return fixed_queue_try_dequeue(btif_media_cb.TxAaQ);
}
/*******************************************************************************
......@@ -2515,7 +2520,7 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame)
if (p_buf == NULL)
{
APPL_TRACE_ERROR ("ERROR btif_media_aa_prep_sbc_2_send no buffer TxCnt %d ",
GKI_queue_length(&btif_media_cb.TxAaQ));
fixed_queue_length(btif_media_cb.TxAaQ));
return;
}
......@@ -2579,15 +2584,15 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame)
{
APPL_TRACE_DEBUG("### tx suspended, discarded frame ###");
if (GKI_queue_length(&btif_media_cb.TxAaQ) > 0)
btif_media_flush_q(&(btif_media_cb.TxAaQ));
if (! fixed_queue_is_empty(btif_media_cb.TxAaQ))
btif_media_flush_q(btif_media_cb.TxAaQ);
GKI_freebuf(p_buf);
return;
}
/* Enqueue the encoded SBC frame in AA Tx Queue */
GKI_enqueue(&(btif_media_cb.TxAaQ), p_buf);
fixed_queue_enqueue(btif_media_cb.TxAaQ, p_buf);
}
else
{
......@@ -2614,14 +2619,15 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame)
if (nb_frame > MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
nb_frame = MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ;
if (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
if (fixed_queue_length(btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
{
APPL_TRACE_WARNING("%s() - TX queue buffer count %d/%d", __func__,
GKI_queue_length(&btif_media_cb.TxAaQ), MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
fixed_queue_length(btif_media_cb.TxAaQ),
MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
}
while (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
GKI_freebuf(GKI_dequeue(&(btif_media_cb.TxAaQ)));
while (fixed_queue_length(btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
GKI_freebuf(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
// Transcode frame
......
......@@ -77,7 +77,7 @@ typedef struct l2cap_socket {
struct packet *first_packet; //fist packet to be delivered to app
struct packet *last_packet; //last packet to be delivered to app
BUFFER_Q incoming_que; //data that came in but has not yet been read
fixed_queue_t *incoming_que; //data that came in but has not yet been read
unsigned fixed_chan :1; //fixed channel (or psm?)
unsigned server :1; //is a server? (or connecting?)
unsigned connected :1; //is connected?
......
......@@ -4,7 +4,6 @@ include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/common \
$(LOCAL_PATH)/ulinux \
$(LOCAL_PATH)/../btcore/include \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../stack/include \
......@@ -20,8 +19,7 @@ LOCAL_CFLAGS += \
endif
LOCAL_SRC_FILES := \
./common/gki_buffer.c \
./ulinux/gki_ulinux.c
./common/gki_buffer.c
LOCAL_MODULE := libbt-brcm_gki
LOCAL_MODULE_TAGS := optional
......
......@@ -17,12 +17,10 @@
static_library("gki") {
sources = [
"common/gki_buffer.c",
"ulinux/gki_ulinux.c",
]
include_dirs = [
"common",
"ulinux",
"//",
"//include",
"//stack/include",
......
......@@ -42,16 +42,6 @@ typedef struct _tle
UINT8 in_use;
} TIMER_LIST_ENT;
/***********************************************************************
** This queue is a general purpose buffer queue, for application use.
*/
typedef struct
{
void *_p_first;
void *_p_last;
UINT16 _count;
} BUFFER_Q;
/***********************************************************************
** Function prototypes
*/
......@@ -61,16 +51,3 @@ typedef struct
void GKI_freebuf (void *);
void *GKI_getbuf (UINT16);
UINT16 GKI_get_buf_size (void *);
/* User buffer queue management
*/
void *GKI_dequeue (BUFFER_Q *);
void GKI_enqueue (BUFFER_Q *, void *);
void *GKI_getfirst (BUFFER_Q *);
void *GKI_getlast (BUFFER_Q *);
void *GKI_getnext (void *);
void GKI_init_q (BUFFER_Q *);
UINT16 GKI_queue_length(BUFFER_Q *);
BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
void *GKI_remove_from_queue (BUFFER_Q *, void *);
......@@ -20,169 +20,15 @@
#include <stdlib.h>
#include "osi/include/allocator.h"
#include "osi/include/mutex.h"
#include "gki_int.h"
#include "gki.h"
#if (GKI_NUM_TOTAL_BUF_POOLS > 16)
#error Number of pools out of range (16 Max)!
#endif
#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
/*******************************************************************************
**
** Function gki_init_free_queue
**
** Description Internal function called at startup to initialize a free
** queue. It is called once for each free queue.
**
** Returns void
**
*******************************************************************************/
static void gki_init_free_queue (UINT8 id, UINT16 size, UINT16 total, void *p_mem)
{
UINT16 i;
UINT16 act_size;
BUFFER_HDR_T *hdr;
BUFFER_HDR_T *hdr1 = NULL;
UINT32 *magic;
INT32 tempsize = size;
tGKI_COM_CB *p_cb = &gki_cb.com;
/* Ensure an even number of longwords */
tempsize = (INT32)ALIGN_POOL(size);
act_size = (UINT16)(tempsize + BUFFER_PADDING_SIZE);
/* Remember pool start and end addresses */
if(p_mem)
{
p_cb->pool_start[id] = (UINT8 *)p_mem;
p_cb->pool_end[id] = (UINT8 *)p_mem + (act_size * total);
}
p_cb->pool_size[id] = act_size;
p_cb->freeq[id].size = (UINT16) tempsize;
p_cb->freeq[id].total = total;
p_cb->freeq[id].cur_cnt = 0;
p_cb->freeq[id].max_cnt = 0;
/* Initialize index table */
if(p_mem)
{
hdr = (BUFFER_HDR_T *)p_mem;
p_cb->freeq[id]._p_first = hdr;
for (i = 0; i < total; i++)
{
hdr->q_id = id;
hdr->status = BUF_STATUS_FREE;
magic = (UINT32 *)((UINT8 *)hdr + BUFFER_HDR_SIZE + tempsize);
*magic = MAGIC_NO;
hdr1 = hdr;
hdr = (BUFFER_HDR_T *)((UINT8 *)hdr + act_size);
hdr1->p_next = hdr;
}
hdr1->p_next = NULL;
p_cb->freeq[id]._p_last = hdr1;
}
}
void gki_buffer_cleanup(void)
typedef struct _buffer_hdr
{
UINT8 i;
tGKI_COM_CB *p_cb = &gki_cb.com;
UINT8 q_id; /* id of the queue */
UINT16 size;
} BUFFER_HDR_T;
for (i=0; i < GKI_NUM_FIXED_BUF_POOLS; i++)
{
if ( 0 < p_cb->freeq[i].max_cnt )
{
osi_free(p_cb->pool_start[i]);
p_cb->freeq[i].cur_cnt = 0;
p_cb->freeq[i].max_cnt = 0;
p_cb->freeq[i]._p_first = NULL;
p_cb->freeq[i]._p_last = NULL;
p_cb->pool_start[i] = NULL;
p_cb->pool_end[i] = NULL;
p_cb->pool_size[i] = 0;
}
}
}
/*******************************************************************************
**
** Function gki_buffer_init
**
** Description Called once internally by GKI at startup to initialize all
** buffers and free buffer pools.
**
** Returns void
**
*******************************************************************************/
void gki_buffer_init(void)
{
static const struct {
uint16_t size;
uint16_t count;
} buffer_info[GKI_NUM_FIXED_BUF_POOLS] = {
{ GKI_BUF0_SIZE, GKI_BUF0_MAX },
{ GKI_BUF1_SIZE, GKI_BUF1_MAX },
{ GKI_BUF2_SIZE, GKI_BUF2_MAX },
{ GKI_BUF3_SIZE, GKI_BUF3_MAX },
{ GKI_BUF4_SIZE, GKI_BUF4_MAX },
{ GKI_BUF5_SIZE, GKI_BUF5_MAX },
{ GKI_BUF6_SIZE, GKI_BUF6_MAX },
{ GKI_BUF7_SIZE, GKI_BUF7_MAX },
{ GKI_BUF8_SIZE, GKI_BUF8_MAX },
{ GKI_BUF9_SIZE, GKI_BUF9_MAX },
};
tGKI_COM_CB *p_cb = &gki_cb.com;
for (int i = 0; i < GKI_NUM_TOTAL_BUF_POOLS; i++)
{
p_cb->pool_start[i] = NULL;
p_cb->pool_end[i] = NULL;
p_cb->pool_size[i] = 0;
p_cb->freeq[i]._p_first = 0;
p_cb->freeq[i]._p_last = 0;
p_cb->freeq[i].size = 0;
p_cb->freeq[i].total = 0;
p_cb->freeq[i].cur_cnt = 0;
p_cb->freeq[i].max_cnt = 0;
}
/* Use default from target.h */
p_cb->pool_access_mask = GKI_DEF_BUFPOOL_PERM_MASK;
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);
}
}
/*******************************************************************************
**
** Function GKI_init_q
**
** Description Called by an application to initialize a buffer queue.
**
** Returns void
**
*******************************************************************************/
void GKI_init_q (BUFFER_Q *p_q)
{
p_q->_p_first = p_q->_p_last = NULL;
p_q->_count = 0;
}
#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */
/*******************************************************************************
**
......@@ -199,9 +45,6 @@ void GKI_init_q (BUFFER_Q *p_q)
void *GKI_getbuf (UINT16 size)
{
BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
header->status = BUF_STATUS_UNLINKED;
header->p_next = NULL;
header->Type = 0;
header->size = size;
return header + 1;
}
......@@ -240,216 +83,3 @@ UINT16 GKI_get_buf_size (void *p_buf)
BUFFER_HDR_T *header = (BUFFER_HDR_T *)p_buf - 1;
return header->size;
}
/*******************************************************************************
**
** Function GKI_enqueue
**
** Description Enqueue a buffer at the tail of the queue
**
** Parameters: p_q - (input) pointer to a queue.
** p_buf - (input) address of the buffer to enqueue
**
** Returns void
**
*******************************************************************************/
void GKI_enqueue (BUFFER_Q *p_q, void *p_buf)
{
BUFFER_HDR_T *p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
assert(p_hdr->status == BUF_STATUS_UNLINKED);
mutex_global_lock();
/* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
if (p_q->_p_last)
{
BUFFER_HDR_T *_p_last_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_last - BUFFER_HDR_SIZE);
_p_last_hdr->p_next = p_hdr;
}
else
p_q->_p_first = p_buf;
p_q->_p_last = p_buf;
p_q->_count++;
p_hdr->p_next = NULL;
p_hdr->status = BUF_STATUS_QUEUED;
mutex_global_unlock();
}
/*******************************************************************************
**
** Function GKI_dequeue
**
** Description Dequeues a buffer from the head of a queue
**
** Parameters: p_q - (input) pointer to a queue.
**
** Returns NULL if queue is empty, else buffer
**
*******************************************************************************/
void *GKI_dequeue (BUFFER_Q *p_q)
{
BUFFER_HDR_T *p_hdr;
mutex_global_lock();
if (!p_q || !p_q->_count)
{
mutex_global_unlock();
return (NULL);
}
p_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_first - BUFFER_HDR_SIZE);
/* Keep buffers such that GKI header is invisible
*/
if (p_hdr->p_next)
p_q->_p_first = ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
else
{
p_q->_p_first = NULL;
p_q->_p_last = NULL;
}
p_q->_count--;
p_hdr->p_next = NULL;
p_hdr->status = BUF_STATUS_UNLINKED;
mutex_global_unlock();
return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
}
/*******************************************************************************
**
** Function GKI_remove_from_queue
**
** Description Dequeue a buffer from the middle of the queue
**
** Parameters: p_q - (input) pointer to a queue.
** p_buf - (input) address of the buffer to enqueue
**
** Returns NULL if queue is empty, else buffer
**
*******************************************************************************/
void *GKI_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
{
BUFFER_HDR_T *p_prev;
BUFFER_HDR_T *p_buf_hdr;
mutex_global_lock();
if (p_buf == p_q->_p_first)
{
mutex_global_unlock();
return (GKI_dequeue (p_q));
}
p_buf_hdr = (BUFFER_HDR_T *)((UINT8 *)p_buf - BUFFER_HDR_SIZE);
p_prev = (BUFFER_HDR_T *)((UINT8 *)p_q->_p_first - BUFFER_HDR_SIZE);
for ( ; p_prev; p_prev = p_prev->p_next)
{
/* If the previous points to this one, move the pointers around */
if (p_prev->p_next == p_buf_hdr)
{
p_prev->p_next = p_buf_hdr->p_next;
/* If we are removing the last guy in the queue, update _p_last */
if (p_buf == p_q->_p_last)
p_q->_p_last = p_prev + 1;
/* One less in the queue */
p_q->_count--;
/* The buffer is now unlinked */
p_buf_hdr->p_next = NULL;
p_buf_hdr->status = BUF_STATUS_UNLINKED;
mutex_global_unlock();
return (p_buf);
}
}
mutex_global_unlock();
return (NULL);
}
/*******************************************************************************
**
** Function GKI_getfirst
**
** Description Return a pointer to the first buffer in a queue
**
** Parameters: p_q - (input) pointer to a queue.
**
** Returns NULL if queue is empty, else buffer address
**
*******************************************************************************/
void *GKI_getfirst (BUFFER_Q *p_q)
{
return (p_q->_p_first);
}
/*******************************************************************************
**
** Function GKI_getlast
**
** Description Return a pointer to the last buffer in a queue
**
** Parameters: p_q - (input) pointer to a queue.
**
** Returns NULL if queue is empty, else buffer address
**
*******************************************************************************/
void *GKI_getlast (BUFFER_Q *p_q)
{
return (p_q->_p_last);
}
/*******************************************************************************
**
** Function GKI_getnext
**
** Description Return a pointer to the next buffer in a queue
**
** Parameters: p_buf - (input) pointer to the buffer to find the next one from.
**
** Returns NULL if no more buffers in the queue, else next buffer address
**
*******************************************************************************/
void *GKI_getnext (void *p_buf)
{
BUFFER_HDR_T *p_hdr;
p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
if (p_hdr->p_next)
return ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
else
return (NULL);
}
/*******************************************************************************
**
** Function GKI_queue_is_empty
**
** Description Check the status of a queue.
**
** Parameters: p_q - (input) pointer to a queue.
**
** Returns TRUE if queue is empty, else FALSE
**
*******************************************************************************/
BOOLEAN GKI_queue_is_empty(BUFFER_Q *p_q)
{
return ((BOOLEAN) (p_q->_count == 0));
}
UINT16 GKI_queue_length(BUFFER_Q *p_q)
{
return p_q->_count;
}
/******************************************************************************
*
* Copyright (C) 1999-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#pragma once
#include "gki.h"
typedef struct _buffer_hdr
{
struct _buffer_hdr *p_next; /* next buffer in the queue */
UINT8 q_id; /* id of the queue */
UINT8 status; /* FREE, UNLINKED or QUEUED */
UINT8 Type;
UINT16 size;
} BUFFER_HDR_T;
typedef struct _free_queue
{
BUFFER_HDR_T *_p_first; /* first buffer in the queue */
BUFFER_HDR_T *_p_last; /* last buffer in the queue */
UINT16 size; /* size of the buffers in the pool */
UINT16 total; /* toatal number of buffers */
UINT16 cur_cnt; /* number of buffers currently allocated */
UINT16 max_cnt; /* maximum number of buffers allocated at any time */
} FREE_QUEUE_T;
/* Put all GKI variables into one control block
*/
typedef struct
{
/* Define the buffer pool management variables
*/
FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS];
UINT16 pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS];
/* Define the buffer pool start addresses
*/
UINT8 *pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the start of each buffer pool */
UINT8 *pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of each buffer pool */
UINT16 pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in a pool */
/* Define the buffer pool access control variables */
UINT16 pool_access_mask; /* Bits are set if the corresponding buffer pool is a restricted pool */
} tGKI_COM_CB;
/* Internal GKI function prototypes
*/
void gki_buffer_init(void);
void gki_buffer_cleanup(void);
/******************************************************************************
*
* Copyright (C) 1999-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#pragma once
#include "gki_common.h"
typedef struct
{
tGKI_COM_CB com;
} tGKI_CB;
extern tGKI_CB gki_cb;
/******************************************************************************
*
* Copyright (C) 2009-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#define LOG_TAG "bt_gki"
#include <assert.h>
#include <string.h>
#include "btcore/include/module.h"
#include "gki/ulinux/gki_int.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
tGKI_CB gki_cb;
static future_t *init(void) {
memset(&gki_cb, 0, sizeof(gki_cb));
gki_buffer_init();
return NULL;
}
static future_t *clean_up(void) {
gki_buffer_cleanup();
return NULL;
}
// Temp module until GKI dies
EXPORT_SYMBOL const module_t gki_module = {
.name = GKI_MODULE,
.init = init,
.start_up = NULL,
.shut_down = NULL,
.clean_up = clean_up,
.dependencies = {
NULL
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment