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_REFCOUNT_H_
17 #define _IA_CSS_REFCOUNT_H_
18 
19 #include <type_support.h>
20 #include <system_local.h>
21 #include <ia_css_err.h>
22 #include <ia_css_types.h>
23 
24 typedef void (*clear_func)(ia_css_ptr ptr);
25 
26 /*! \brief Function for initializing refcount list
27  *
28  * \param[in]	size		Size of the refcount list.
29  * \return				ia_css_err
30  */
31 int ia_css_refcount_init(uint32_t size);
32 
33 /*! \brief Function for de-initializing refcount list
34  *
35  * \return				None
36  */
37 void ia_css_refcount_uninit(void);
38 
39 /*! \brief Function for increasing reference by 1.
40  *
41  * \param[in]	id		ID of the object.
42  * \param[in]	ptr		Data of the object (ptr).
43  * \return				ia_css_ptr (saved address)
44  */
45 ia_css_ptr ia_css_refcount_increment(s32 id, ia_css_ptr ptr);
46 
47 /*! \brief Function for decrease reference by 1.
48  *
49  * \param[in]	id		ID of the object.
50  * \param[in]	ptr		Data of the object (ptr).
51  *
52  *	- true, if it is successful.
53  *	- false, otherwise.
54  */
55 bool ia_css_refcount_decrement(s32 id, ia_css_ptr ptr);
56 
57 /*! \brief Function to check if reference count is 1.
58  *
59  * \param[in]	ptr		Data of the object (ptr).
60  *
61  *	- true, if it is successful.
62  *	- false, otherwise.
63  */
64 bool ia_css_refcount_is_single(ia_css_ptr ptr);
65 
66 /*! \brief Function to clear reference list objects.
67  *
68  * \param[in]	id			ID of the object.
69  * \param[in] clear_func	function to be run to free reference objects.
70  *
71  *  return				None
72  */
73 void ia_css_refcount_clear(s32 id,
74 			   clear_func clear_func_ptr);
75 
76 /*! \brief Function to verify if object is valid
77  *
78  * \param[in] ptr       Data of the object (ptr)
79  *
80  *      - true, if valid
81  *      - false, if invalid
82  */
83 bool ia_css_refcount_is_valid(ia_css_ptr ptr);
84 
85 #endif /* _IA_CSS_REFCOUNT_H_ */
86