1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  */
6 
7 #ifndef _IA_CSS_CIRCBUF_COMM_H
8 #define _IA_CSS_CIRCBUF_COMM_H
9 
10 #include <linux/build_bug.h>
11 
12 #include <type_support.h>  /* uint8_t, uint32_t */
13 
14 #define IA_CSS_CIRCBUF_PADDING 1 /* The circular buffer is implemented in lock-less manner, wherein
15 				   * the head and tail can advance independently without any locks.
16 				   * But to achieve this, an extra buffer element is required to detect
17 				   * queue full & empty conditions, wherein the tail trails the head for
18 				   * full and is equal to head for empty condition. This causes 1 buffer
19 				   * not being available for use.
20 				   */
21 
22 /****************************************************************
23  *
24  * Portable Data structures
25  *
26  ****************************************************************/
27 /**
28  * @brief Data structure for the circular descriptor.
29  */
30 typedef struct ia_css_circbuf_desc_s ia_css_circbuf_desc_t;
31 struct ia_css_circbuf_desc_s {
32 	u8 size;	/* the maximum number of elements*/
33 	u8 step;   /* number of bytes per element */
34 	u8 start;	/* index of the oldest element */
35 	u8 end;	/* index at which to write the new element */
36 };
37 
38 #define SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT				\
39 	(4 * sizeof(uint8_t))
40 
41 static_assert(sizeof(struct ia_css_circbuf_desc_s) == SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT);
42 
43 /**
44  * @brief Data structure for the circular buffer element.
45  */
46 typedef struct ia_css_circbuf_elem_s ia_css_circbuf_elem_t;
47 struct ia_css_circbuf_elem_s {
48 	u32 val;	/* the value stored in the element */
49 };
50 
51 #define SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT				\
52 	(sizeof(uint32_t))
53 
54 static_assert(sizeof(struct ia_css_circbuf_elem_s) == SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT);
55 
56 #endif /*_IA_CSS_CIRCBUF_COMM_H*/
57