Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 169d8207 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 242cebd2
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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
+0 −2
Original line number Diff line number Diff line
@@ -17,12 +17,10 @@
static_library("gki") {
  sources = [
    "common/gki_buffer.c",
    "ulinux/gki_ulinux.c",
  ]

  include_dirs = [
    "common",
    "ulinux",
    "//",
    "//include",
    "//stack/include",
+0 −23
Original line number Diff line number Diff line
@@ -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 *);
+6 −376
Original line number Diff line number Diff line
@@ -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)
{
    UINT8   i;
    tGKI_COM_CB *p_cb = &gki_cb.com;

    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++)
typedef struct _buffer_hdr
{
        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;
	UINT8   q_id;                 /* id of the queue */
        UINT16  size;
} BUFFER_HDR_T;

    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;
}

gki/common/gki_common.h

deleted100644 → 0
+0 −65
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  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);
Loading