xref: /linux/drivers/staging/media/atomisp/pci/base/circbuf/interface/ia_css_circbuf_comm.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef _IA_CSS_CIRCBUF_COMM_H
17 #define _IA_CSS_CIRCBUF_COMM_H
18 
19 #include <linux/build_bug.h>
20 
21 #include <type_support.h>  /* uint8_t, uint32_t */
22 
23 #define IA_CSS_CIRCBUF_PADDING 1 /* The circular buffer is implemented in lock-less manner, wherein
24 				   * the head and tail can advance independently without any locks.
25 				   * But to achieve this, an extra buffer element is required to detect
26 				   * queue full & empty conditions, wherein the tail trails the head for
27 				   * full and is equal to head for empty condition. This causes 1 buffer
28 				   * not being available for use.
29 				   */
30 
31 /****************************************************************
32  *
33  * Portable Data structures
34  *
35  ****************************************************************/
36 /**
37  * @brief Data structure for the circular descriptor.
38  */
39 typedef struct ia_css_circbuf_desc_s ia_css_circbuf_desc_t;
40 struct ia_css_circbuf_desc_s {
41 	u8 size;	/* the maximum number of elements*/
42 	u8 step;   /* number of bytes per element */
43 	u8 start;	/* index of the oldest element */
44 	u8 end;	/* index at which to write the new element */
45 };
46 
47 #define SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT				\
48 	(4 * sizeof(uint8_t))
49 
50 static_assert(sizeof(struct ia_css_circbuf_desc_s) == SIZE_OF_IA_CSS_CIRCBUF_DESC_S_STRUCT);
51 
52 /**
53  * @brief Data structure for the circular buffer element.
54  */
55 typedef struct ia_css_circbuf_elem_s ia_css_circbuf_elem_t;
56 struct ia_css_circbuf_elem_s {
57 	u32 val;	/* the value stored in the element */
58 };
59 
60 #define SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT				\
61 	(sizeof(uint32_t))
62 
63 static_assert(sizeof(struct ia_css_circbuf_elem_s) == SIZE_OF_IA_CSS_CIRCBUF_ELEM_S_STRUCT);
64 
65 #endif /*_IA_CSS_CIRCBUF_COMM_H*/
66