2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __RESOURCE_MANAGER_H__
18 #define __RESOURCE_MANAGER_H__
27 #define SYSCOMMON_RESMAN_BUFF_MAX 255
29 enum syscommon_resman_listener_type;
31 struct syscommon_resman_resource_attribute;
32 struct syscommon_resman_resource_control;
34 struct syscommon_resman_array_value {
40 struct syscommon_resman_resource_attribute_value {
45 struct syscommon_resman_resource_attribute_ops {
46 int (*set)(int resource_id,
47 const struct syscommon_resman_resource_attribute *attr,
48 const void *data, int count);
49 int (*get)(int resource_id,
50 const struct syscommon_resman_resource_attribute *attr,
53 * If .is_supported ops is not implemented, use .get ops in order to
54 * check whether the resource attribute is supported or not.
56 bool (*is_supported)(int resource_id,
57 const struct syscommon_resman_resource_attribute *attr);
60 struct syscommon_resman_resource_attribute_listener_ops {
61 int (*init)(int resource_id, const struct syscommon_resman_resource_attribute *attr);
62 void (*exit)(int resource_id, const struct syscommon_resman_resource_attribute *attr);
63 void (*action)(int resource_id, const struct syscommon_resman_resource_attribute *attr,
64 void *param, enum syscommon_resman_listener_type listener_type);
67 struct syscommon_resman_resource_attribute {
68 const char name[SYSCOMMON_RESMAN_BUFF_MAX];
72 const struct syscommon_resman_resource_attribute_ops ops;
73 const struct syscommon_resman_resource_attribute_listener_ops listener_ops;
76 struct syscommon_resman_resource_control_ops {
77 const int (*set)(int resource_id,
78 const struct syscommon_resman_resource_control *ctrl,
80 const int (*get)(int resource_id,
81 const struct syscommon_resman_resource_control *ctrl,
85 struct syscommon_resman_resource_control {
86 const char name[SYSCOMMON_RESMAN_BUFF_MAX];
88 const struct syscommon_resman_resource_control_ops ops;
91 struct syscommon_resman_resource_driver_ops {
94 int (*create)(int resource_id);
95 void (*delete)(int resource_id);
97 * If prepare_update is specified, it will be called
98 * at every update_resource_attrs().
100 int (*prepare_update)(int resource_id);
103 struct syscommon_resman_resource_driver {
106 const u_int64_t flag;
108 const struct syscommon_resman_resource_attribute *attrs;
110 const struct syscommon_resman_resource_control *ctrls;
111 const struct syscommon_resman_resource_driver_ops ops;
114 #define SYSCOMMON_RESMAN_RESOURCE_DRIVER_REGISTER(resource_driver) \
115 static void __attribute__((constructor)) __syscommon_resman_module_init(void) \
117 syscommon_resman_add_resource_driver(resource_driver); \
119 static void __attribute__((destructor)) __syscommon_resman_module_exit(void) \
121 syscommon_resman_remove_resource_driver(resource_driver); \
124 /* Add/remove resource driver and device */
125 const struct syscommon_resman_resource_driver *
126 syscommon_resman_find_resource_driver(int resource_type);
127 void syscommon_resman_add_resource_driver(const struct syscommon_resman_resource_driver *resource_driver);
128 void syscommon_resman_remove_resource_driver(const struct syscommon_resman_resource_driver *resource_driver);
130 /* Create/delete resource instance */
131 int syscommon_resman_create_resource(int *resource_id, int resource_type);
132 void syscommon_resman_delete_resource(int resource_id);
134 /* Set flag of the resource to given flag mask */
135 int syscommon_resman_set_resource_flag(int resource_id, u_int64_t flag_mask);
137 /* Handle resource control */
138 int syscommon_resman_set_resource_control(int resource_id, u_int64_t ctrl_id, const void *data);
139 const char *syscommon_resman_get_resource_control_name(int resource_id, u_int64_t ctrl_id);
141 /* Handle resource attribute */
142 int syscommon_resman_update_resource_attrs(int resource_id);
143 const struct syscommon_resman_resource_attribute *
144 syscommon_resman_get_resource_attr(int resource_id, u_int64_t attr_id);
145 struct syscommon_resman_resource_attribute_value *
146 syscommon_resman_get_resource_attr_value(int resource_id, u_int64_t attr_id);
147 int syscommon_resman_is_resource_attr_supported(int resource_id, u_int64_t attr_id, bool *supported);
150 syscommon_resman_resource_attr_supported_always(int resource_id,
151 const struct syscommon_resman_resource_attribute *attr)
156 int syscommon_resman_get_resource_attrs_json(int resource_id, char **json_string);
157 int syscommon_resman_get_resource_attr_json(int resource_id, u_int64_t attr_id, char **json_string);
158 int syscommon_resman_get_resource_list_json(char **json_string);
160 int syscommon_resman_get_resource_attr_int(int resource_id, u_int64_t attr_id, int32_t *data);
161 int syscommon_resman_get_resource_attr_int_sync(int resource_id, u_int64_t attr_id, int32_t *data);
162 int syscommon_resman_get_resource_attr_int64(int resource_id, u_int64_t attr_id, int64_t *data);
163 int syscommon_resman_get_resource_attr_int64_sync(int resource_id, u_int64_t attr_id, int64_t *data);
164 int syscommon_resman_get_resource_attr_uint(int resource_id, u_int64_t attr_id, u_int32_t *data);
165 int syscommon_resman_get_resource_attr_uint_sync(int resource_id, u_int64_t attr_id, u_int32_t *data);
166 int syscommon_resman_get_resource_attr_uint64(int resource_id, u_int64_t attr_id, u_int64_t *data);
167 int syscommon_resman_get_resource_attr_uint64_sync(int resource_id, u_int64_t attr_id, u_int64_t *data);
168 int syscommon_resman_get_resource_attr_double(int resource_id, u_int64_t attr_id, double *data);
169 int syscommon_resman_get_resource_attr_double_sync(int resource_id, u_int64_t attr_id, double *data);
170 int syscommon_resman_get_resource_attr_string(int resource_id, u_int64_t attr_id, char *data);
171 int syscommon_resman_get_resource_attr_string_sync(int resource_id, u_int64_t attr_id, char *data);
172 int syscommon_resman_get_resource_attr_array(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data);
173 int syscommon_resman_get_resource_attr_array_sync(int resource_id, u_int64_t attr_id, struct syscommon_resman_array_value **data);
174 int syscommon_resman_get_resource_attr_ptr(int resource_id, u_int64_t attr_id, void **data);
175 int syscommon_resman_get_resource_attr_ptr_sync(int resource_id, u_int64_t attr_id, void **data);
177 int syscommon_resman_set_resource_attr_interest(int resource_id, u_int64_t interest_mask);
178 int syscommon_resman_unset_resource_attr_interest(int resource_id, u_int64_t interest_mask);
179 bool syscommon_resman_is_resource_attr_interested(int resource_id, u_int64_t interest_mask);
180 const char *syscommon_resman_get_resource_attr_name(int resource_id, u_int64_t attr_id);
182 const char *syscommon_resman_get_resource_name(int resource_id);
183 void *syscommon_resman_get_resource_privdata(int resource_id);
184 int syscommon_resman_get_resource_type(int resource_id);
186 int syscommon_resman_set_resource_privdata(int resource_id, void *priv);
188 void syscommon_resman_init_resource_drivers(void);
189 void syscommon_resman_exit_resource_drivers(void);