blob: 066f2224fe64e8327a72f4d63f24cf68869c9952 [file] [log] [blame]
/*
* Copyright (C) 2018 Synaptics Incorporated. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND
* SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY
* INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR
* CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE
* OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND
* BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF
* COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT
* DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY
* TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS.
*/
#define _FRAMEQUEUE_C_
#include "common.h"
#include "framequeue.h"
#include "util.h"
#define WRAPAROUND(a) (((a) >= MAX_NUM_FRAMES) ? 0:(a))
/******************************************************************************
* FUNCTION: reset frame queue to be empty state
* PARAMS: *frmq - pionter to a frame queue
*
******************************************************************************/
void frmq_reset(FRAMEQUEUE *frmq)
{
/* reset read/write pointer of frame queue */
/* the frame queue is empty when read pointer equals write pointer */
frmq->shadow_head = 0;
frmq->head = 0;
frmq->tail = 0;
/* reset frame pointers to NULL in frame queue */
UtilMemSet(frmq->frame_descrs, 0, sizeof(void *)*MAX_NUM_FRAMES);
return;
}
/******************************************************************************
* FUNCTION: push a frame descriptor into frame queue
* PARAMS: *frmq - pointer to frame queue
* *frm_descr - pointer to a frame descriptor
* RETURN: 1 - succeed
* 0 - fail: frame queue is full
******************************************************************************/
int frmq_push(FRAMEQUEUE *frmq, void *frm_descr)
{
/* first check whether frame queue is full */
if (WRAPAROUND(frmq->tail+1) == frmq->head)
return 0;
/* push frame descriptor into frame queue if not full */
frmq->frame_descrs[frmq->tail] = frm_descr;
/* update shadow write pointer */
frmq->tail = WRAPAROUND(frmq->tail+1);
return 1;
}
/******************************************************************************
* FUNCTION: pop a frame descriptor out of a frame queue
* but actually without update head pointer.
* PARAMS: *frmq - pointer to a frame queue
* **frm_descr - pointer to the frame descriptor
* RETURN: 1 - succeed
* 0 - command queue is empty, no command is available
* NOTE: use pop_commit to actually update head pointer.
******************************************************************************/
int frmq_pop(FRAMEQUEUE *frmq, void **frm_descr)
{
/* first check whether frame queue is empty */
if (frmq->head == frmq->tail)
return 0;
/* pop a frame descriptor from frame queue if not empty */
*frm_descr = frmq->frame_descrs[frmq->head];
/* update shadow read pointer */
frmq->shadow_head = WRAPAROUND(frmq->head+1);
return 1;
}
/******************************************************************************
* FUNCTION: commit previous pop operation
* by actually update head pointer.
* PARAMS: *frmq - pointer to a frame queue
* RETURN: 1 - succeed
* 0 - command queue is empty, no command is available
******************************************************************************/
int frmq_pop_commit(FRAMEQUEUE *frmq)
{
/* update shadow read pointer */
frmq->head = frmq->shadow_head;
return 1;
}