forked from Mirrors/opensbi

This patch does following improvements to sbi_fifo: 1. Use valid SBI_Exxxx error codes instead of -1 2. The sbi_fifo_is_full() and sbi_fifo_is_empty() did not acquire qlock before accessing head and tail hence fixed it 3. Added avail member for ease in debugging and simplifying head/tail updates. Due to above changes size of sbi_fifo changes from 48 bytes to 56 bytes. Signed-off-by: Anup Patel <anup.patel@wdc.com>
37 lines
867 B
C
37 lines
867 B
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
|
*
|
|
* Authors:
|
|
* Atish Patra<atish.patra@wdc.com>
|
|
*
|
|
*/
|
|
|
|
#ifndef __SBI_FIFO_H__
|
|
#define __SBI_FIFO_H__
|
|
|
|
#include <sbi/riscv_locks.h>
|
|
#include <sbi/sbi_types.h>
|
|
|
|
struct sbi_fifo {
|
|
/* Static members of struct */
|
|
void *queue;
|
|
unsigned long entry_size;
|
|
unsigned long num_entries;
|
|
/* Dynamic members of struct protected by lock */
|
|
spinlock_t qlock;
|
|
unsigned long avail;
|
|
unsigned long head;
|
|
unsigned long tail;
|
|
};
|
|
|
|
int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data);
|
|
int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data);
|
|
void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem,
|
|
unsigned long entries, unsigned long entry_size);
|
|
bool sbi_fifo_is_empty(struct sbi_fifo *fifo);
|
|
bool sbi_fifo_is_full(struct sbi_fifo *fifo);
|
|
|
|
#endif
|