Lines Matching +full:bool +full:- +full:property
2 * Thunderbolt XDomain property support
43 bool is_root);
55 static bool tb_property_entry_valid(const struct tb_property_entry *entry, in tb_property_entry_valid()
58 switch (entry->type) { in tb_property_entry_valid()
62 if (entry->length > block_len) in tb_property_entry_valid()
64 if (entry->value + entry->length > block_len) in tb_property_entry_valid()
69 if (entry->length != 1) in tb_property_entry_valid()
77 static bool tb_property_key_valid(const char *key) in tb_property_key_valid()
85 struct tb_property *property; in tb_property_alloc() local
87 property = kzalloc(sizeof(*property), GFP_KERNEL); in tb_property_alloc()
88 if (!property) in tb_property_alloc()
91 strcpy(property->key, key); in tb_property_alloc()
92 property->type = type; in tb_property_alloc()
93 INIT_LIST_HEAD(&property->list); in tb_property_alloc()
95 return property; in tb_property_alloc()
102 struct tb_property *property; in tb_property_parse() local
111 property = tb_property_alloc(key, entry->type); in tb_property_parse()
112 if (!property) in tb_property_parse()
115 property->length = entry->length; in tb_property_parse()
117 switch (property->type) { in tb_property_parse()
119 dir = __tb_property_parse_dir(block, block_len, entry->value, in tb_property_parse()
120 entry->length, false); in tb_property_parse()
122 kfree(property); in tb_property_parse()
125 property->value.dir = dir; in tb_property_parse()
129 property->value.data = kcalloc(property->length, sizeof(u32), in tb_property_parse()
131 if (!property->value.data) { in tb_property_parse()
132 kfree(property); in tb_property_parse()
135 parse_dwdata(property->value.data, block + entry->value, in tb_property_parse()
136 entry->length); in tb_property_parse()
140 property->value.text = kcalloc(property->length, sizeof(u32), in tb_property_parse()
142 if (!property->value.text) { in tb_property_parse()
143 kfree(property); in tb_property_parse()
146 parse_dwdata(property->value.text, block + entry->value, in tb_property_parse()
147 entry->length); in tb_property_parse()
149 property->value.text[property->length * 4 - 1] = '\0'; in tb_property_parse()
153 property->value.immediate = entry->value; in tb_property_parse()
157 property->type = TB_PROPERTY_TYPE_UNKNOWN; in tb_property_parse()
161 return property; in tb_property_parse()
165 size_t block_len, unsigned int dir_offset, size_t dir_len, bool is_root) in __tb_property_parse_dir()
180 dir->uuid = kmemdup(&block[dir_offset], sizeof(*dir->uuid), in __tb_property_parse_dir()
183 content_len = dir_len - 4; /* Length includes UUID */ in __tb_property_parse_dir()
189 INIT_LIST_HEAD(&dir->properties); in __tb_property_parse_dir()
192 struct tb_property *property; in __tb_property_parse_dir() local
194 property = tb_property_parse(block, block_len, &entries[i]); in __tb_property_parse_dir()
195 if (!property) { in __tb_property_parse_dir()
200 list_add_tail(&property->list, &dir->properties); in __tb_property_parse_dir()
207 * tb_property_parse_dir() - Parses properties from given property block
208 * @block: Property block to parse
209 * @block_len: Number of dword elements in the property block
225 if (rootdir->magic != TB_PROPERTY_ROOTDIR_MAGIC) in tb_property_parse_dir()
227 if (rootdir->length > block_len) in tb_property_parse_dir()
230 return __tb_property_parse_dir(block, block_len, 0, rootdir->length, in tb_property_parse_dir()
235 * tb_property_create_dir() - Creates new property directory
238 * Creates new, empty property directory. If @uuid is %NULL then the
249 INIT_LIST_HEAD(&dir->properties); in tb_property_create_dir()
251 dir->uuid = kmemdup(uuid, sizeof(*dir->uuid), GFP_KERNEL); in tb_property_create_dir()
252 if (!dir->uuid) { in tb_property_create_dir()
262 static void tb_property_free(struct tb_property *property) in tb_property_free() argument
264 switch (property->type) { in tb_property_free()
266 tb_property_free_dir(property->value.dir); in tb_property_free()
270 kfree(property->value.data); in tb_property_free()
274 kfree(property->value.text); in tb_property_free()
281 kfree(property); in tb_property_free()
285 * tb_property_free_dir() - Release memory allocated for property directory
294 struct tb_property *property, *tmp; in tb_property_free_dir() local
299 list_for_each_entry_safe(property, tmp, &dir->properties, list) { in tb_property_free_dir()
300 list_del(&property->list); in tb_property_free_dir()
301 tb_property_free(property); in tb_property_free_dir()
303 kfree(dir->uuid); in tb_property_free_dir()
309 bool recurse, size_t *data_len) in tb_property_dir_length()
311 const struct tb_property *property; in tb_property_dir_length() local
314 if (dir->uuid) in tb_property_dir_length()
315 len += sizeof(*dir->uuid) / 4; in tb_property_dir_length()
319 list_for_each_entry(property, &dir->properties, list) { in tb_property_dir_length()
322 switch (property->type) { in tb_property_dir_length()
326 property->value.dir, recurse, data_len); in tb_property_dir_length()
336 *data_len += property->length; in tb_property_dir_length()
351 const struct tb_property *property; in __tb_property_format_dir() local
357 * The structure of property block looks like following. Leaf in __tb_property_format_dir()
361 * +----------+ <-- start_offset in __tb_property_format_dir()
362 * | header | <-- root directory header in __tb_property_format_dir()
363 * +----------+ --- in __tb_property_format_dir()
364 * | entry 0 | -^--------------------. in __tb_property_format_dir()
365 * +----------+ | | in __tb_property_format_dir()
366 * | entry 1 | -|--------------------|--. in __tb_property_format_dir()
367 * +----------+ | | | in __tb_property_format_dir()
368 * | entry 2 | -|-----------------. | | in __tb_property_format_dir()
369 * +----------+ | | | | in __tb_property_format_dir()
373 * +----------+ | | | | in __tb_property_format_dir()
375 * +----------+ <-- data_offset | | | in __tb_property_format_dir()
376 * | data 0 | <------------------|--' | in __tb_property_format_dir()
377 * +----------+ | | in __tb_property_format_dir()
378 * | data 1 | <------------------|-----' in __tb_property_format_dir()
379 * +----------+ | in __tb_property_format_dir()
381 * +----------+ <-- dir_end <------' in __tb_property_format_dir()
382 * | UUID | <-- directory UUID (child directory) in __tb_property_format_dir()
383 * +----------+ in __tb_property_format_dir()
385 * +----------+ in __tb_property_format_dir()
387 * +----------+ in __tb_property_format_dir()
391 * +----------+ in __tb_property_format_dir()
393 * +----------+ in __tb_property_format_dir()
395 * +----------+ in __tb_property_format_dir()
406 return -EINVAL; in __tb_property_format_dir()
408 return -EINVAL; in __tb_property_format_dir()
411 if (dir->uuid) { in __tb_property_format_dir()
415 memcpy(pe->uuid, dir->uuid, sizeof(pe->uuid)); in __tb_property_format_dir()
416 entry = pe->entries; in __tb_property_format_dir()
421 re->magic = TB_PROPERTY_ROOTDIR_MAGIC; in __tb_property_format_dir()
422 re->length = dir_len - sizeof(*re) / 4; in __tb_property_format_dir()
423 entry = re->entries; in __tb_property_format_dir()
426 list_for_each_entry(property, &dir->properties, list) { in __tb_property_format_dir()
429 format_dwdata(entry, property->key, 2); in __tb_property_format_dir()
430 entry->type = property->type; in __tb_property_format_dir()
432 switch (property->type) { in __tb_property_format_dir()
434 child = property->value.dir; in __tb_property_format_dir()
439 entry->length = tb_property_dir_length(child, false, in __tb_property_format_dir()
441 entry->value = dir_end; in __tb_property_format_dir()
446 format_dwdata(&block[data_offset], property->value.data, in __tb_property_format_dir()
447 property->length); in __tb_property_format_dir()
448 entry->length = property->length; in __tb_property_format_dir()
449 entry->value = data_offset; in __tb_property_format_dir()
450 data_offset += entry->length; in __tb_property_format_dir()
454 format_dwdata(&block[data_offset], property->value.text, in __tb_property_format_dir()
455 property->length); in __tb_property_format_dir()
456 entry->length = property->length; in __tb_property_format_dir()
457 entry->value = data_offset; in __tb_property_format_dir()
458 data_offset += entry->length; in __tb_property_format_dir()
462 entry->length = property->length; in __tb_property_format_dir()
463 entry->value = property->value.immediate; in __tb_property_format_dir()
477 * tb_property_format_dir() - Formats directory to the packed XDomain format
479 * @block: Property block where the packed data is placed
480 * @block_len: Length of the property block
504 * tb_property_add_immediate() - Add immediate property to directory
505 * @parent: Directory to add the property
506 * @key: Key for the property
507 * @value: Immediate value to store with the property
512 struct tb_property *property; in tb_property_add_immediate() local
515 return -EINVAL; in tb_property_add_immediate()
517 property = tb_property_alloc(key, TB_PROPERTY_TYPE_VALUE); in tb_property_add_immediate()
518 if (!property) in tb_property_add_immediate()
519 return -ENOMEM; in tb_property_add_immediate()
521 property->length = 1; in tb_property_add_immediate()
522 property->value.immediate = value; in tb_property_add_immediate()
524 list_add_tail(&property->list, &parent->properties); in tb_property_add_immediate()
530 * tb_property_add_data() - Adds arbitrary data property to directory
531 * @parent: Directory to add the property
532 * @key: Key for the property
543 struct tb_property *property; in tb_property_add_data() local
546 return -EINVAL; in tb_property_add_data()
548 property = tb_property_alloc(key, TB_PROPERTY_TYPE_DATA); in tb_property_add_data()
549 if (!property) in tb_property_add_data()
550 return -ENOMEM; in tb_property_add_data()
552 property->length = size / 4; in tb_property_add_data()
553 property->value.data = kzalloc(size, GFP_KERNEL); in tb_property_add_data()
554 if (!property->value.data) { in tb_property_add_data()
555 kfree(property); in tb_property_add_data()
556 return -ENOMEM; in tb_property_add_data()
559 memcpy(property->value.data, buf, buflen); in tb_property_add_data()
561 list_add_tail(&property->list, &parent->properties); in tb_property_add_data()
567 * tb_property_add_text() - Adds string property to directory
568 * @parent: Directory to add the property
569 * @key: Key for the property
579 struct tb_property *property; in tb_property_add_text() local
582 return -EINVAL; in tb_property_add_text()
584 property = tb_property_alloc(key, TB_PROPERTY_TYPE_TEXT); in tb_property_add_text()
585 if (!property) in tb_property_add_text()
586 return -ENOMEM; in tb_property_add_text()
588 property->length = size / 4; in tb_property_add_text()
589 property->value.text = kzalloc(size, GFP_KERNEL); in tb_property_add_text()
590 if (!property->value.text) { in tb_property_add_text()
591 kfree(property); in tb_property_add_text()
592 return -ENOMEM; in tb_property_add_text()
595 strcpy(property->value.text, text); in tb_property_add_text()
597 list_add_tail(&property->list, &parent->properties); in tb_property_add_text()
603 * tb_property_add_dir() - Adds a directory to the parent directory
604 * @parent: Directory to add the property
605 * @key: Key for the property
611 struct tb_property *property; in tb_property_add_dir() local
614 return -EINVAL; in tb_property_add_dir()
616 property = tb_property_alloc(key, TB_PROPERTY_TYPE_DIRECTORY); in tb_property_add_dir()
617 if (!property) in tb_property_add_dir()
618 return -ENOMEM; in tb_property_add_dir()
620 property->value.dir = dir; in tb_property_add_dir()
622 list_add_tail(&property->list, &parent->properties); in tb_property_add_dir()
628 * tb_property_remove() - Removes property from a parent directory
629 * @property: Property to remove
631 * Note memory for @property is released as well so it is not allowed to
634 void tb_property_remove(struct tb_property *property) in tb_property_remove() argument
636 list_del(&property->list); in tb_property_remove()
637 kfree(property); in tb_property_remove()
642 * tb_property_find() - Find a property from a directory
643 * @dir: Directory where the property is searched
645 * @type: Type of the property
647 * Finds and returns property from the given directory. Does not recurse
648 * into sub-directories. Returns %NULL if the property was not found.
653 struct tb_property *property; in tb_property_find() local
655 list_for_each_entry(property, &dir->properties, list) { in tb_property_find()
656 if (property->type == type && !strcmp(property->key, key)) in tb_property_find()
657 return property; in tb_property_find()
665 * tb_property_get_next() - Get next property from directory
667 * @prev: Previous property in the directory (%NULL returns the first)
673 if (list_is_last(&prev->list, &dir->properties)) in tb_property_get_next()
677 return list_first_entry_or_null(&dir->properties, struct tb_property, in tb_property_get_next()