| 1 | // SPDX-License-Identifier: LGPL-2.1-or-latercxx . . $ `<file>/lib/line-config.c`/ |
| 2 | // SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <errno.h> |
| 6 | #include <gpiod.h>cxx . . $ `<file>/include/gpiod.h`/ |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include <sys/param.h> |
| 10 | |
| 11 | #include "internal.h"cxx . . $ `<file>/lib/internal.h`/ |
| 12 | |
| 13 | #define LINES_MAXcxx . . $ `lib/line-config.c:13:9`! (GPIO_V2_LINES_MAXcxx . . $ `lib/uapi/gpio.h:45:9`!) |
| 14 | |
| 15 | struct settings_nodecxx . . $ settings_node# { |
| 16 | struct settings_nodecxx . . $ settings_node# *prevcxx . . $ settings_node#prev.; |
| 17 | struct settings_nodecxx . . $ settings_node# *nextcxx . . $ settings_node#next.; |
| 18 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settingscxx . . $ settings_node#settings.; |
| 19 | unsigned int refcntcxx . . $ settings_node#refcnt.; |
| 20 | }; |
| 21 | |
| 22 | struct per_line_configcxx . . $ per_line_config# { |
| 23 | unsigned int offsetcxx . . $ per_line_config#offset.; |
| 24 | struct settings_nodecxx . . $ settings_node# *nodecxx . . $ per_line_config#node.; |
| 25 | }; |
| 26 | |
| 27 | struct gpiod_line_configcxx . . $ gpiod_line_config# { |
| 28 | struct per_line_configcxx . . $ per_line_config# line_configscxx . . $ gpiod_line_config#line_configs.[LINES_MAXcxx . . $ `lib/line-config.c:13:9`!]; |
| 29 | size_t num_configscxx . . $ gpiod_line_config#num_configs.; |
| 30 | enum gpiod_line_valuecxx . . $ gpiod_line_value# output_valuescxx . . $ gpiod_line_config#output_values.[LINES_MAXcxx . . $ `lib/line-config.c:13:9`!]; |
| 31 | size_t num_output_valuescxx . . $ gpiod_line_config#num_output_values.; |
| 32 | struct settings_nodecxx . . $ settings_node# *sref_listcxx . . $ gpiod_line_config#sref_list.; |
| 33 | }; |
| 34 | |
| 35 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! struct gpiod_line_configcxx . . $ gpiod_line_config# *gpiod_line_config_newcxx . . $ gpiod_line_config_new(77901d00aed55c9f).(void) |
| 36 | { |
| 37 | struct gpiod_line_configcxx . . $ gpiod_line_config# *config; |
| 38 | |
| 39 | config = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*config)); |
| 40 | if (!config) |
| 41 | return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 42 | |
| 43 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(config, 0, sizeof(*config)); |
| 44 | |
| 45 | return config; |
| 46 | } |
| 47 | |
| 48 | static void free_refscxx . . $ free_refs(fa2e7b721f5ca4e3).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 49 | { |
| 50 | struct settings_nodecxx . . $ settings_node# *node, *tmp; |
| 51 | |
| 52 | for (node = config->sref_listcxx . . $ gpiod_line_config#sref_list.; node;) { |
| 53 | tmp = node->nextcxx . . $ settings_node#next.; |
| 54 | gpiod_line_settings_freecxx . . $ gpiod_line_settings_free(d2d57b119af88c6b).(node->settingscxx . . $ settings_node#settings.); |
| 55 | freecxx . . $ free(5d22bdacc48458e8).(node); |
| 56 | node = tmp; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void gpiod_line_config_freecxx . . $ gpiod_line_config_free(fa2e7b721f5ca4e3).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 61 | { |
| 62 | if (!config) |
| 63 | return; |
| 64 | |
| 65 | free_refscxx . . $ free_refs(fa2e7b721f5ca4e3).(config); |
| 66 | freecxx . . $ free(5d22bdacc48458e8).(config); |
| 67 | } |
| 68 | |
| 69 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! void gpiod_line_config_resetcxx . . $ gpiod_line_config_reset(fa2e7b721f5ca4e3).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 70 | { |
| 71 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 72 | |
| 73 | free_refscxx . . $ free_refs(fa2e7b721f5ca4e3).(config); |
| 74 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(config, 0, sizeof(*config)); |
| 75 | } |
| 76 | |
| 77 | static struct per_line_configcxx . . $ per_line_config# *find_configcxx . . $ find_config(f71782b8628b8928).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 78 | unsigned int offset) |
| 79 | { |
| 80 | struct per_line_configcxx . . $ per_line_config# *per_line; |
| 81 | size_t i; |
| 82 | |
| 83 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 84 | per_line = &config->line_configscxx . . $ gpiod_line_config#line_configs.[i]; |
| 85 | |
| 86 | if (offset == per_line->offsetcxx . . $ per_line_config#offset.) |
| 87 | return per_line; |
| 88 | } |
| 89 | |
| 90 | return &config->line_configscxx . . $ gpiod_line_config#line_configs.[config->num_configscxx . . $ gpiod_line_config#num_configs.++]; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Count offsets in the input array that would require a new slot in the |
| 95 | * config: those not already present in config->line_configs and not repeated |
| 96 | * earlier in the same offsets array. |
| 97 | */ |
| 98 | static size_t count_new_offsetscxx . . $ count_new_offsets(803585b7e23d1619).(const struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 99 | const unsigned int *offsets, size_t num_offsets) |
| 100 | { |
| 101 | size_t i, j, num_new = 0; |
| 102 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! existing; |
| 103 | |
| 104 | for (i = 0; i < num_offsets; i++) { |
| 105 | existing = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 106 | |
| 107 | for (j = 0; j < config->num_configscxx . . $ gpiod_line_config#num_configs.; j++) { |
| 108 | if (config->line_configscxx . . $ gpiod_line_config#line_configs.[j].offsetcxx . . $ per_line_config#offset. == offsets[i]) { |
| 109 | existing = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if (!existing) { |
| 115 | for (j = 0; j < i; j++) { |
| 116 | if (offsets[j] == offsets[i]) { |
| 117 | existing = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (!existing) |
| 124 | num_new++; |
| 125 | } |
| 126 | |
| 127 | return num_new; |
| 128 | } |
| 129 | |
| 130 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int gpiod_line_config_add_line_settingscxx . . $ gpiod_line_config_add_line_settings(518ec44549dc52c3).( |
| 131 | struct gpiod_line_configcxx . . $ gpiod_line_config# *config, const unsigned int *offsets, |
| 132 | size_t num_offsets, struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 133 | { |
| 134 | struct per_line_configcxx . . $ per_line_config# *per_line; |
| 135 | struct settings_nodecxx . . $ settings_node# *node, *old; |
| 136 | size_t i, new_offsets; |
| 137 | |
| 138 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 139 | |
| 140 | if (!offsets || num_offsets == 0) { |
| 141 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | new_offsets = count_new_offsetscxx . . $ count_new_offsets(803585b7e23d1619).(config, offsets, num_offsets); |
| 146 | |
| 147 | if ((config->num_configscxx . . $ gpiod_line_config#num_configs. + new_offsets) > LINES_MAXcxx . . $ `lib/line-config.c:13:9`!) { |
| 148 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = E2BIGcxx . . $ `<external>/8987895939074593727/errno-base.h:11:9`!; |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | node = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*node)); |
| 153 | if (!node) |
| 154 | return -1; |
| 155 | |
| 156 | if (!settings) |
| 157 | node->settingscxx . . $ settings_node#settings. = gpiod_line_settings_newcxx . . $ gpiod_line_settings_new(15316d376757b079).(); |
| 158 | else |
| 159 | node->settingscxx . . $ settings_node#settings. = gpiod_line_settings_copycxx . . $ gpiod_line_settings_copy(48e7ea08c6f5ee34).(settings); |
| 160 | if (!node->settingscxx . . $ settings_node#settings.) { |
| 161 | freecxx . . $ free(5d22bdacc48458e8).(node); |
| 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | node->refcntcxx . . $ settings_node#refcnt. = 0; |
| 166 | node->nextcxx . . $ settings_node#next. = config->sref_listcxx . . $ gpiod_line_config#sref_list.; |
| 167 | if (config->sref_listcxx . . $ gpiod_line_config#sref_list.) |
| 168 | config->sref_listcxx . . $ gpiod_line_config#sref_list.->prevcxx . . $ settings_node#prev. = node; |
| 169 | node->prevcxx . . $ settings_node#prev. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 170 | config->sref_listcxx . . $ gpiod_line_config#sref_list. = node; |
| 171 | |
| 172 | for (i = 0; i < num_offsets; i++) { |
| 173 | per_line = find_configcxx . . $ find_config(f71782b8628b8928).(config, offsets[i]); |
| 174 | |
| 175 | node->refcntcxx . . $ settings_node#refcnt.++; |
| 176 | per_line->offsetcxx . . $ per_line_config#offset. = offsets[i]; |
| 177 | old = per_line->nodecxx . . $ per_line_config#node.; |
| 178 | per_line->nodecxx . . $ per_line_config#node. = node; |
| 179 | |
| 180 | if (old && !(--old->refcntcxx . . $ settings_node#refcnt.)) { |
| 181 | if (old->prevcxx . . $ settings_node#prev.) |
| 182 | old->prevcxx . . $ settings_node#prev.->nextcxx . . $ settings_node#next. = old->nextcxx . . $ settings_node#next.; |
| 183 | if (old->nextcxx . . $ settings_node#next.) |
| 184 | old->nextcxx . . $ settings_node#next.->prevcxx . . $ settings_node#prev. = old->prevcxx . . $ settings_node#prev.; |
| 185 | gpiod_line_settings_freecxx . . $ gpiod_line_settings_free(d2d57b119af88c6b).(old->settingscxx . . $ settings_node#settings.); |
| 186 | freecxx . . $ free(5d22bdacc48458e8).(old); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! struct gpiod_line_settingscxx . . $ gpiod_line_settings# * |
| 194 | gpiod_line_config_get_line_settingscxx . . $ gpiod_line_config_get_line_settings(d9003ef1532cb2b).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 195 | unsigned int offset) |
| 196 | { |
| 197 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings; |
| 198 | struct per_line_configcxx . . $ per_line_config# *per_line; |
| 199 | size_t i; |
| 200 | int ret; |
| 201 | |
| 202 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 203 | |
| 204 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 205 | per_line = &config->line_configscxx . . $ gpiod_line_config#line_configs.[i]; |
| 206 | |
| 207 | if (per_line->offsetcxx . . $ per_line_config#offset. == offset) { |
| 208 | settings = gpiod_line_settings_copycxx . . $ gpiod_line_settings_copy(48e7ea08c6f5ee34).( |
| 209 | per_line->nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.); |
| 210 | if (!settings) |
| 211 | return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 212 | |
| 213 | /* |
| 214 | * If a global output value was set for this line - use |
| 215 | * it and override the one stored in settings. |
| 216 | */ |
| 217 | if (config->num_output_valuescxx . . $ gpiod_line_config#num_output_values. > i) { |
| 218 | ret = gpiod_line_settings_set_output_valuecxx . . $ gpiod_line_settings_set_output_value(d19601ab04d8b8f9).( |
| 219 | settings, |
| 220 | config->output_valuescxx . . $ gpiod_line_config#output_values.[i]); |
| 221 | if (ret) { |
| 222 | gpiod_line_settings_freecxx . . $ gpiod_line_settings_free(d2d57b119af88c6b).(settings); |
| 223 | return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return settings; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 232 | return NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 233 | } |
| 234 | |
| 235 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! int |
| 236 | gpiod_line_config_set_output_valuescxx . . $ gpiod_line_config_set_output_values(36d92098507954bd).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 237 | const enum gpiod_line_valuecxx . . $ gpiod_line_value# *values, |
| 238 | size_t num_values) |
| 239 | { |
| 240 | size_t i; |
| 241 | int ret; |
| 242 | |
| 243 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 244 | |
| 245 | if (!num_values || num_values > LINES_MAXcxx . . $ `lib/line-config.c:13:9`! || !values) { |
| 246 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | for (i = 0; i < num_values; i++) { |
| 251 | ret = gpiod_set_output_valuecxx . . $ gpiod_set_output_value(eb3e60c472d1bd0b).(values[i], |
| 252 | &config->output_valuescxx . . $ gpiod_line_config#output_values.[i]); |
| 253 | if (ret) { |
| 254 | config->num_output_valuescxx . . $ gpiod_line_config#num_output_values. = 0; |
| 255 | return ret; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | config->num_output_valuescxx . . $ gpiod_line_config#num_output_values. = num_values; |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! size_t |
| 265 | gpiod_line_config_get_num_configured_offsetscxx . . $ gpiod_line_config_get_num_configured_offsets(b6abb7ebb938306b).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 266 | { |
| 267 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 268 | |
| 269 | return config->num_configscxx . . $ gpiod_line_config#num_configs.; |
| 270 | } |
| 271 | |
| 272 | GPIOD_APIcxx . . $ `lib/internal.h:15:9`! size_t |
| 273 | gpiod_line_config_get_configured_offsetscxx . . $ gpiod_line_config_get_configured_offsets(2e31a89dc027cd02).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 274 | unsigned int *offsets, |
| 275 | size_t max_offsets) |
| 276 | { |
| 277 | size_t num_offsets, i; |
| 278 | |
| 279 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`!(config); |
| 280 | |
| 281 | if (!offsets || !max_offsets || !config->num_configscxx . . $ gpiod_line_config#num_configs.) |
| 282 | return 0; |
| 283 | |
| 284 | num_offsets = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(config->num_configs, max_offsets); |
| 285 | |
| 286 | for (i = 0; i < num_offsets; i++) |
| 287 | offsets[i] = config->line_configscxx . . $ gpiod_line_config#line_configs.[i].offsetcxx . . $ per_line_config#offset.; |
| 288 | |
| 289 | return num_offsets; |
| 290 | } |
| 291 | |
| 292 | static void set_offsetscxx . . $ set_offsets(e94979c081436145).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 293 | struct gpio_v2_line_requestcxx . . $ gpio_v2_line_request# *uapi_cfg) |
| 294 | { |
| 295 | size_t i; |
| 296 | |
| 297 | uapi_cfg->num_linescxx . . $ gpio_v2_line_request#num_lines. = config->num_configscxx . . $ gpiod_line_config#num_configs.; |
| 298 | |
| 299 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) |
| 300 | uapi_cfg->offsetscxx . . $ gpio_v2_line_request#offsets.[i] = config->line_configscxx . . $ gpiod_line_config#line_configs.[i].offsetcxx . . $ per_line_config#offset.; |
| 301 | } |
| 302 | |
| 303 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! has_at_least_one_output_directioncxx . . $ has_at_least_one_output_direction(94582bc5214d065a).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 304 | { |
| 305 | size_t i; |
| 306 | |
| 307 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 308 | if (gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).( |
| 309 | config->line_configscxx . . $ gpiod_line_config#line_configs.[i].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.) == |
| 310 | GPIOD_LINE_DIRECTION_OUTPUTcxx . . $ GPIOD_LINE_DIRECTION_OUTPUT.) |
| 311 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 312 | } |
| 313 | |
| 314 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 315 | } |
| 316 | |
| 317 | static void set_output_valuecxx . . $ set_output_value(4846d717a5e9c50f).(uint64_tcxx . . $ uint64_t# *vals, size_t bit, |
| 318 | enum gpiod_line_valuecxx . . $ gpiod_line_value# value) |
| 319 | { |
| 320 | gpiod_line_mask_assign_bitcxx . . $ gpiod_line_mask_assign_bit(aece0c19fb2b7302).(vals, bit, |
| 321 | value == GPIOD_LINE_VALUE_ACTIVEcxx . . $ GPIOD_LINE_VALUE_ACTIVE. ? 1 : 0); |
| 322 | } |
| 323 | |
| 324 | static void set_kernel_output_valuescxx . . $ set_kernel_output_values(23dab2255c8c9885).(uint64_tcxx . . $ uint64_t# *mask, uint64_tcxx . . $ uint64_t# *vals, |
| 325 | struct gpiod_line_configcxx . . $ gpiod_line_config# *config) |
| 326 | { |
| 327 | struct per_line_configcxx . . $ per_line_config# *per_line; |
| 328 | enum gpiod_line_valuecxx . . $ gpiod_line_value# value; |
| 329 | size_t i; |
| 330 | |
| 331 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(mask); |
| 332 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(vals); |
| 333 | |
| 334 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 335 | per_line = &config->line_configscxx . . $ gpiod_line_config#line_configs.[i]; |
| 336 | |
| 337 | if (gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).( |
| 338 | per_line->nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.) != |
| 339 | GPIOD_LINE_DIRECTION_OUTPUTcxx . . $ GPIOD_LINE_DIRECTION_OUTPUT.) |
| 340 | continue; |
| 341 | |
| 342 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(mask, i); |
| 343 | value = gpiod_line_settings_get_output_valuecxx . . $ gpiod_line_settings_get_output_value(10f0a367a2836eed).( |
| 344 | per_line->nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.); |
| 345 | set_output_valuecxx . . $ set_output_value(4846d717a5e9c50f).(vals, i, value); |
| 346 | } |
| 347 | |
| 348 | /* "Global" output values override the ones from per-line settings. */ |
| 349 | for (i = 0; i < config->num_output_valuescxx . . $ gpiod_line_config#num_output_values.; i++) { |
| 350 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(mask, i); |
| 351 | value = config->output_valuescxx . . $ gpiod_line_config#output_values.[i]; |
| 352 | set_output_valuecxx . . $ set_output_value(4846d717a5e9c50f).(vals, i, value); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | static void set_output_valuescxx . . $ set_output_values(555b5e6f389b4b9).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 357 | struct gpio_v2_line_requestcxx . . $ gpio_v2_line_request# *uapi_cfg, |
| 358 | unsigned int *attr_idx) |
| 359 | { |
| 360 | struct gpio_v2_line_config_attributecxx . . $ gpio_v2_line_config_attribute# *attr; |
| 361 | uint64_tcxx . . $ uint64_t# mask, values; |
| 362 | |
| 363 | if (!has_at_least_one_output_directioncxx . . $ has_at_least_one_output_direction(94582bc5214d065a).(config)) |
| 364 | return; |
| 365 | |
| 366 | attr = &uapi_cfg->configcxx . . $ gpio_v2_line_request#config..attrscxx . . $ gpio_v2_line_config#attrs.[(*attr_idx)++]; |
| 367 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..idcxx . . $ gpio_v2_line_attribute#id. = GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUEScxx . . $ GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES.; |
| 368 | set_kernel_output_valuescxx . . $ set_kernel_output_values(23dab2255c8c9885).(&mask, &values, config); |
| 369 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..valuescxx . . $ gpio_v2_line_attribute#$anonymous_type_0#values. = values; |
| 370 | attr->maskcxx . . $ gpio_v2_line_config_attribute#mask. = mask; |
| 371 | } |
| 372 | |
| 373 | static int set_debounce_periodscxx . . $ set_debounce_periods(9988667e68cc05d4).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 374 | struct gpio_v2_line_configcxx . . $ gpio_v2_line_config# *uapi_cfg, |
| 375 | unsigned int *attr_idx) |
| 376 | { |
| 377 | struct gpio_v2_line_config_attributecxx . . $ gpio_v2_line_config_attribute# *attr; |
| 378 | unsigned long period_i, period_j; |
| 379 | uint64_tcxx . . $ uint64_t# done, mask; |
| 380 | size_t i, j; |
| 381 | |
| 382 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(&done); |
| 383 | |
| 384 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 385 | if (gpiod_line_mask_test_bitcxx . . $ gpiod_line_mask_test_bit(1e1585c25ba0c69a).(&done, i)) |
| 386 | continue; |
| 387 | |
| 388 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&done, i); |
| 389 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(&mask); |
| 390 | |
| 391 | period_i = gpiod_line_settings_get_debounce_period_uscxx . . $ gpiod_line_settings_get_debounce_period_us(f5b4f890d2432d8e).( |
| 392 | config->line_configscxx . . $ gpiod_line_config#line_configs.[i].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.); |
| 393 | if (!period_i) |
| 394 | continue; |
| 395 | |
| 396 | if (*attr_idx == GPIO_V2_LINE_NUM_ATTRS_MAXcxx . . $ `lib/uapi/gpio.h:51:9`!) { |
| 397 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = E2BIGcxx . . $ `<external>/8987895939074593727/errno-base.h:11:9`!; |
| 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | attr = &uapi_cfg->attrscxx . . $ gpio_v2_line_config#attrs.[(*attr_idx)++]; |
| 402 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..idcxx . . $ gpio_v2_line_attribute#id. = GPIO_V2_LINE_ATTR_ID_DEBOUNCEcxx . . $ GPIO_V2_LINE_ATTR_ID_DEBOUNCE.; |
| 403 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..debounce_period_uscxx . . $ gpio_v2_line_attribute#$anonymous_type_0#debounce_period_us. = period_i; |
| 404 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&mask, i); |
| 405 | |
| 406 | for (j = i; j < config->num_configscxx . . $ gpiod_line_config#num_configs.; j++) { |
| 407 | period_j = gpiod_line_settings_get_debounce_period_uscxx . . $ gpiod_line_settings_get_debounce_period_us(f5b4f890d2432d8e).( |
| 408 | config->line_configscxx . . $ gpiod_line_config#line_configs.[j].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.); |
| 409 | if (period_i == period_j) { |
| 410 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&mask, j); |
| 411 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&done, j); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | attr->maskcxx . . $ gpio_v2_line_config_attribute#mask. = mask; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static uint64_tcxx . . $ uint64_t# make_kernel_flagscxx . . $ make_kernel_flags(f5b4f890d2432d8e).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings) |
| 422 | { |
| 423 | uint64_tcxx . . $ uint64_t# flags = 0; |
| 424 | |
| 425 | switch (gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).(settings)) { |
| 426 | case GPIOD_LINE_DIRECTION_INPUTcxx . . $ GPIOD_LINE_DIRECTION_INPUT.: |
| 427 | flags |= GPIO_V2_LINE_FLAG_INPUTcxx . . $ GPIO_V2_LINE_FLAG_INPUT.; |
| 428 | break; |
| 429 | case GPIOD_LINE_DIRECTION_OUTPUTcxx . . $ GPIOD_LINE_DIRECTION_OUTPUT.: |
| 430 | flags |= GPIO_V2_LINE_FLAG_OUTPUTcxx . . $ GPIO_V2_LINE_FLAG_OUTPUT.; |
| 431 | break; |
| 432 | default: |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | switch (gpiod_line_settings_get_edge_detectioncxx . . $ gpiod_line_settings_get_edge_detection(6b75dd760a1e8450).(settings)) { |
| 437 | case GPIOD_LINE_EDGE_FALLINGcxx . . $ GPIOD_LINE_EDGE_FALLING.: |
| 438 | flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLINGcxx . . $ GPIO_V2_LINE_FLAG_EDGE_FALLING. | |
| 439 | GPIO_V2_LINE_FLAG_INPUTcxx . . $ GPIO_V2_LINE_FLAG_INPUT.); |
| 440 | break; |
| 441 | case GPIOD_LINE_EDGE_RISINGcxx . . $ GPIOD_LINE_EDGE_RISING.: |
| 442 | flags |= (GPIO_V2_LINE_FLAG_EDGE_RISINGcxx . . $ GPIO_V2_LINE_FLAG_EDGE_RISING. | |
| 443 | GPIO_V2_LINE_FLAG_INPUTcxx . . $ GPIO_V2_LINE_FLAG_INPUT.); |
| 444 | break; |
| 445 | case GPIOD_LINE_EDGE_BOTHcxx . . $ GPIOD_LINE_EDGE_BOTH.: |
| 446 | flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLINGcxx . . $ GPIO_V2_LINE_FLAG_EDGE_FALLING. | |
| 447 | GPIO_V2_LINE_FLAG_EDGE_RISINGcxx . . $ GPIO_V2_LINE_FLAG_EDGE_RISING. | |
| 448 | GPIO_V2_LINE_FLAG_INPUTcxx . . $ GPIO_V2_LINE_FLAG_INPUT.); |
| 449 | break; |
| 450 | default: |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | switch (gpiod_line_settings_get_drivecxx . . $ gpiod_line_settings_get_drive(7253675e15045b0a).(settings)) { |
| 455 | case GPIOD_LINE_DRIVE_OPEN_DRAINcxx . . $ GPIOD_LINE_DRIVE_OPEN_DRAIN.: |
| 456 | flags |= GPIO_V2_LINE_FLAG_OPEN_DRAINcxx . . $ GPIO_V2_LINE_FLAG_OPEN_DRAIN.; |
| 457 | break; |
| 458 | case GPIOD_LINE_DRIVE_OPEN_SOURCEcxx . . $ GPIOD_LINE_DRIVE_OPEN_SOURCE.: |
| 459 | flags |= GPIO_V2_LINE_FLAG_OPEN_SOURCEcxx . . $ GPIO_V2_LINE_FLAG_OPEN_SOURCE.; |
| 460 | break; |
| 461 | default: |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | switch (gpiod_line_settings_get_biascxx . . $ gpiod_line_settings_get_bias(2211030472337353).(settings)) { |
| 466 | case GPIOD_LINE_BIAS_DISABLEDcxx . . $ GPIOD_LINE_BIAS_DISABLED.: |
| 467 | flags |= GPIO_V2_LINE_FLAG_BIAS_DISABLEDcxx . . $ GPIO_V2_LINE_FLAG_BIAS_DISABLED.; |
| 468 | break; |
| 469 | case GPIOD_LINE_BIAS_PULL_UPcxx . . $ GPIOD_LINE_BIAS_PULL_UP.: |
| 470 | flags |= GPIO_V2_LINE_FLAG_BIAS_PULL_UPcxx . . $ GPIO_V2_LINE_FLAG_BIAS_PULL_UP.; |
| 471 | break; |
| 472 | case GPIOD_LINE_BIAS_PULL_DOWNcxx . . $ GPIOD_LINE_BIAS_PULL_DOWN.: |
| 473 | flags |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWNcxx . . $ GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN.; |
| 474 | break; |
| 475 | default: |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | if (gpiod_line_settings_get_active_lowcxx . . $ gpiod_line_settings_get_active_low(f826ec49283cb6f8).(settings)) |
| 480 | flags |= GPIO_V2_LINE_FLAG_ACTIVE_LOWcxx . . $ GPIO_V2_LINE_FLAG_ACTIVE_LOW.; |
| 481 | |
| 482 | switch (gpiod_line_settings_get_event_clockcxx . . $ gpiod_line_settings_get_event_clock(dd685642e0d57a9c).(settings)) { |
| 483 | case GPIOD_LINE_CLOCK_REALTIMEcxx . . $ GPIOD_LINE_CLOCK_REALTIME.: |
| 484 | flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIMEcxx . . $ GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME.; |
| 485 | break; |
| 486 | case GPIOD_LINE_CLOCK_HTEcxx . . $ GPIOD_LINE_CLOCK_HTE.: |
| 487 | flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTEcxx . . $ GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE.; |
| 488 | break; |
| 489 | default: |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | return flags; |
| 494 | } |
| 495 | |
| 496 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! settings_equalcxx . . $ settings_equal(b23da3539c0325d2).(struct gpiod_line_settingscxx . . $ gpiod_line_settings# *left, |
| 497 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *right) |
| 498 | { |
| 499 | if (gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).(left) != |
| 500 | gpiod_line_settings_get_directioncxx . . $ gpiod_line_settings_get_direction(20fd03fc78c7b03e).(right)) |
| 501 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 502 | |
| 503 | if (gpiod_line_settings_get_edge_detectioncxx . . $ gpiod_line_settings_get_edge_detection(6b75dd760a1e8450).(left) != |
| 504 | gpiod_line_settings_get_edge_detectioncxx . . $ gpiod_line_settings_get_edge_detection(6b75dd760a1e8450).(right)) |
| 505 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 506 | |
| 507 | if (gpiod_line_settings_get_biascxx . . $ gpiod_line_settings_get_bias(2211030472337353).(left) != |
| 508 | gpiod_line_settings_get_biascxx . . $ gpiod_line_settings_get_bias(2211030472337353).(right)) |
| 509 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 510 | |
| 511 | if (gpiod_line_settings_get_drivecxx . . $ gpiod_line_settings_get_drive(7253675e15045b0a).(left) != |
| 512 | gpiod_line_settings_get_drivecxx . . $ gpiod_line_settings_get_drive(7253675e15045b0a).(right)) |
| 513 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 514 | |
| 515 | if (gpiod_line_settings_get_active_lowcxx . . $ gpiod_line_settings_get_active_low(f826ec49283cb6f8).(left) != |
| 516 | gpiod_line_settings_get_active_lowcxx . . $ gpiod_line_settings_get_active_low(f826ec49283cb6f8).(right)) |
| 517 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 518 | |
| 519 | if (gpiod_line_settings_get_event_clockcxx . . $ gpiod_line_settings_get_event_clock(dd685642e0d57a9c).(left) != |
| 520 | gpiod_line_settings_get_event_clockcxx . . $ gpiod_line_settings_get_event_clock(dd685642e0d57a9c).(right)) |
| 521 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 522 | |
| 523 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 524 | } |
| 525 | |
| 526 | static int set_flagscxx . . $ set_flags(9988667e68cc05d4).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 527 | struct gpio_v2_line_configcxx . . $ gpio_v2_line_config# *uapi_cfg, |
| 528 | unsigned int *attr_idx) |
| 529 | { |
| 530 | struct gpiod_line_settingscxx . . $ gpiod_line_settings# *settings_i, *settings_j; |
| 531 | struct gpio_v2_line_config_attributecxx . . $ gpio_v2_line_config_attribute# *attr; |
| 532 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! globals_taken = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 533 | uint64_tcxx . . $ uint64_t# done, mask; |
| 534 | size_t i, j; |
| 535 | |
| 536 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(&done); |
| 537 | |
| 538 | for (i = 0; i < config->num_configscxx . . $ gpiod_line_config#num_configs.; i++) { |
| 539 | if (gpiod_line_mask_test_bitcxx . . $ gpiod_line_mask_test_bit(1e1585c25ba0c69a).(&done, i)) |
| 540 | continue; |
| 541 | |
| 542 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&done, i); |
| 543 | |
| 544 | settings_i = config->line_configscxx . . $ gpiod_line_config#line_configs.[i].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.; |
| 545 | |
| 546 | if (!globals_taken) { |
| 547 | globals_taken = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 548 | uapi_cfg->flagscxx . . $ gpio_v2_line_config#flags. = make_kernel_flagscxx . . $ make_kernel_flags(f5b4f890d2432d8e).(settings_i); |
| 549 | |
| 550 | for (j = i; j < config->num_configscxx . . $ gpiod_line_config#num_configs.; j++) { |
| 551 | settings_j = |
| 552 | config->line_configscxx . . $ gpiod_line_config#line_configs.[j].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.; |
| 553 | if (settings_equalcxx . . $ settings_equal(b23da3539c0325d2).(settings_i, settings_j)) |
| 554 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&done, j); |
| 555 | } |
| 556 | } else { |
| 557 | gpiod_line_mask_zerocxx . . $ gpiod_line_mask_zero(386f4d2be08c489b).(&mask); |
| 558 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&mask, i); |
| 559 | |
| 560 | if (*attr_idx == GPIO_V2_LINE_NUM_ATTRS_MAXcxx . . $ `lib/uapi/gpio.h:51:9`!) { |
| 561 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = E2BIGcxx . . $ `<external>/8987895939074593727/errno-base.h:11:9`!; |
| 562 | return -1; |
| 563 | } |
| 564 | |
| 565 | attr = &uapi_cfg->attrscxx . . $ gpio_v2_line_config#attrs.[(*attr_idx)++]; |
| 566 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..idcxx . . $ gpio_v2_line_attribute#id. = GPIO_V2_LINE_ATTR_ID_FLAGScxx . . $ GPIO_V2_LINE_ATTR_ID_FLAGS.; |
| 567 | attr->attrcxx . . $ gpio_v2_line_config_attribute#attr..flagscxx . . $ gpio_v2_line_attribute#$anonymous_type_0#flags. = make_kernel_flagscxx . . $ make_kernel_flags(f5b4f890d2432d8e).(settings_i); |
| 568 | |
| 569 | for (j = i; j < config->num_configscxx . . $ gpiod_line_config#num_configs.; j++) { |
| 570 | settings_j = |
| 571 | config->line_configscxx . . $ gpiod_line_config#line_configs.[j].nodecxx . . $ per_line_config#node.->settingscxx . . $ settings_node#settings.; |
| 572 | if (settings_equalcxx . . $ settings_equal(b23da3539c0325d2).(settings_i, settings_j)) { |
| 573 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&done, j); |
| 574 | gpiod_line_mask_set_bitcxx . . $ gpiod_line_mask_set_bit(5e61894bc0b8b7).(&mask, j); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | attr->maskcxx . . $ gpio_v2_line_config_attribute#mask. = mask; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | int gpiod_line_config_to_uapicxx . . $ gpiod_line_config_to_uapi(180b8730a233f01).(struct gpiod_line_configcxx . . $ gpiod_line_config# *config, |
| 586 | struct gpio_v2_line_requestcxx . . $ gpio_v2_line_request# *uapi_cfg) |
| 587 | { |
| 588 | unsigned int attr_idx = 0; |
| 589 | int ret; |
| 590 | |
| 591 | set_offsetscxx . . $ set_offsets(e94979c081436145).(config, uapi_cfg); |
| 592 | set_output_valuescxx . . $ set_output_values(555b5e6f389b4b9).(config, uapi_cfg, &attr_idx); |
| 593 | |
| 594 | ret = set_debounce_periodscxx . . $ set_debounce_periods(9988667e68cc05d4).(config, &uapi_cfg->configcxx . . $ gpio_v2_line_request#config., &attr_idx); |
| 595 | if (ret) |
| 596 | return -1; |
| 597 | |
| 598 | ret = set_flagscxx . . $ set_flags(9988667e68cc05d4).(config, &uapi_cfg->configcxx . . $ gpio_v2_line_request#config., &attr_idx); |
| 599 | if (ret) |
| 600 | return -1; |
| 601 | |
| 602 | uapi_cfg->configcxx . . $ gpio_v2_line_request#config..num_attrscxx . . $ gpio_v2_line_config#num_attrs. = attr_idx; |
| 603 | |
| 604 | return 0; |
| 605 | } |