Lines Matching +full:child +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
31 kfree(mtd->name); in free_partition()
37 WARN_ON(!list_empty(&mtd->part.node)); in release_mtd_partition()
46 int wr_alignment = (parent->flags & MTD_NO_ERASE) ? in allocate_partition()
47 master->writesize : master->erasesize; in allocate_partition()
49 parent->part.size : parent->size; in allocate_partition()
50 struct mtd_info *child; in allocate_partition() local
56 child = kzalloc(sizeof(*child), GFP_KERNEL); in allocate_partition()
57 name = kstrdup(part->name, GFP_KERNEL); in allocate_partition()
58 if (!name || !child) { in allocate_partition()
60 parent->name); in allocate_partition()
62 kfree(child); in allocate_partition()
63 return ERR_PTR(-ENOMEM); in allocate_partition()
67 child->type = parent->type; in allocate_partition()
68 child->part.flags = parent->flags & ~part->mask_flags; in allocate_partition()
69 child->part.flags |= part->add_flags; in allocate_partition()
70 child->flags = child->part.flags; in allocate_partition()
71 child->part.size = part->size; in allocate_partition()
72 child->writesize = parent->writesize; in allocate_partition()
73 child->writebufsize = parent->writebufsize; in allocate_partition()
74 child->oobsize = parent->oobsize; in allocate_partition()
75 child->oobavail = parent->oobavail; in allocate_partition()
76 child->subpage_sft = parent->subpage_sft; in allocate_partition()
78 child->name = name; in allocate_partition()
79 child->owner = parent->owner; in allocate_partition()
83 * However, it is very useful to have the master node present, in allocate_partition()
89 child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? in allocate_partition()
90 &parent->dev : parent->dev.parent; in allocate_partition()
91 child->dev.of_node = part->of_node; in allocate_partition()
92 child->parent = parent; in allocate_partition()
93 child->part.offset = part->offset; in allocate_partition()
94 INIT_LIST_HEAD(&child->partitions); in allocate_partition()
96 if (child->part.offset == MTDPART_OFS_APPEND) in allocate_partition()
97 child->part.offset = cur_offset; in allocate_partition()
98 if (child->part.offset == MTDPART_OFS_NXTBLK) { in allocate_partition()
100 child->part.offset = cur_offset; in allocate_partition()
103 child->part.offset += wr_alignment - remainder; in allocate_partition()
105 "0x%012llx -> 0x%012llx\n", partno, in allocate_partition()
107 child->part.offset); in allocate_partition()
110 if (child->part.offset == MTDPART_OFS_RETAIN) { in allocate_partition()
111 child->part.offset = cur_offset; in allocate_partition()
112 if (parent_size - child->part.offset >= child->part.size) { in allocate_partition()
113 child->part.size = parent_size - child->part.offset - in allocate_partition()
114 child->part.size; in allocate_partition()
117 part->name, parent_size - child->part.offset, in allocate_partition()
118 child->part.size); in allocate_partition()
123 if (child->part.size == MTDPART_SIZ_FULL) in allocate_partition()
124 child->part.size = parent_size - child->part.offset; in allocate_partition()
126 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", in allocate_partition()
127 child->part.offset, child->part.offset + child->part.size, in allocate_partition()
128 child->name); in allocate_partition()
131 if (child->part.offset >= parent_size) { in allocate_partition()
133 child->part.offset = 0; in allocate_partition()
134 child->part.size = 0; in allocate_partition()
136 /* Initialize ->erasesize to make add_mtd_device() happy. */ in allocate_partition()
137 child->erasesize = parent->erasesize; in allocate_partition()
138 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", in allocate_partition()
139 part->name); in allocate_partition()
142 if (child->part.offset + child->part.size > parent->size) { in allocate_partition()
143 child->part.size = parent_size - child->part.offset; in allocate_partition()
144 …printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncate… in allocate_partition()
145 part->name, parent->name, child->part.size); in allocate_partition()
148 if (parent->numeraseregions > 1) { in allocate_partition()
150 int i, max = parent->numeraseregions; in allocate_partition()
151 u64 end = child->part.offset + child->part.size; in allocate_partition()
152 struct mtd_erase_region_info *regions = parent->eraseregions; in allocate_partition()
156 for (i = 0; i < max && regions[i].offset <= child->part.offset; in allocate_partition()
161 i--; in allocate_partition()
165 if (child->erasesize < regions[i].erasesize) in allocate_partition()
166 child->erasesize = regions[i].erasesize; in allocate_partition()
168 BUG_ON(child->erasesize == 0); in allocate_partition()
171 child->erasesize = master->erasesize; in allocate_partition()
175 * Child erasesize might differ from the parent one if the parent in allocate_partition()
179 if (!(child->flags & MTD_NO_ERASE)) in allocate_partition()
180 wr_alignment = child->erasesize; in allocate_partition()
182 tmp = mtd_get_master_ofs(child, 0); in allocate_partition()
184 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
188 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
189 …WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n", in allocate_partition()
190 part->name); in allocate_partition()
193 tmp = mtd_get_master_ofs(child, 0) + child->part.size; in allocate_partition()
195 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
196 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
197 …printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n… in allocate_partition()
198 part->name); in allocate_partition()
201 child->size = child->part.size; in allocate_partition()
202 child->ecc_step_size = parent->ecc_step_size; in allocate_partition()
203 child->ecc_strength = parent->ecc_strength; in allocate_partition()
204 child->bitflip_threshold = parent->bitflip_threshold; in allocate_partition()
206 if (master->_block_isbad) { in allocate_partition()
209 while (offs < child->part.size) { in allocate_partition()
210 if (mtd_block_isreserved(child, offs)) in allocate_partition()
211 child->ecc_stats.bbtblocks++; in allocate_partition()
212 else if (mtd_block_isbad(child, offs)) in allocate_partition()
213 child->ecc_stats.badblocks++; in allocate_partition()
214 offs += child->erasesize; in allocate_partition()
219 return child; in allocate_partition()
227 return sysfs_emit(buf, "%lld\n", mtd->part.offset); in offset_show()
238 int ret = sysfs_create_files(&new->dev.kobj, mtd_partition_attrs); in mtd_add_partition_attrs()
250 parent->part.size : parent->size; in mtd_add_partition()
252 struct mtd_info *child; in mtd_add_partition() local
258 return -EINVAL; in mtd_add_partition()
261 length = parent_size - offset; in mtd_add_partition()
264 return -EINVAL; in mtd_add_partition()
271 child = allocate_partition(parent, &part, -1, offset); in mtd_add_partition()
272 if (IS_ERR(child)) in mtd_add_partition()
273 return PTR_ERR(child); in mtd_add_partition()
275 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
276 list_add_tail(&child->part.node, &parent->partitions); in mtd_add_partition()
277 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
279 ret = add_mtd_device(child); in mtd_add_partition()
283 mtd_add_partition_attrs(child); in mtd_add_partition()
288 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
289 list_del(&child->part.node); in mtd_add_partition()
290 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
292 free_partition(child); in mtd_add_partition()
299 * __mtd_del_partition - delete MTD partition
307 struct mtd_info *child, *next; in __mtd_del_partition() local
310 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __mtd_del_partition()
311 err = __mtd_del_partition(child); in __mtd_del_partition()
316 sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs); in __mtd_del_partition()
318 list_del_init(&mtd->part.node); in __mtd_del_partition()
332 struct mtd_info *child, *next; in __del_mtd_partitions() local
335 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __del_mtd_partitions()
336 if (mtd_has_partitions(child)) in __del_mtd_partitions()
337 __del_mtd_partitions(child); in __del_mtd_partitions()
339 pr_info("Deleting %s MTD partition\n", child->name); in __del_mtd_partitions()
340 list_del_init(&child->part.node); in __del_mtd_partitions()
341 ret = del_mtd_device(child); in __del_mtd_partitions()
344 child->name, ret); in __del_mtd_partitions()
358 pr_info("Deleting MTD partitions on \"%s\":\n", mtd->name); in del_mtd_partitions()
360 mutex_lock(&master->master.partitions_lock); in del_mtd_partitions()
362 mutex_unlock(&master->master.partitions_lock); in del_mtd_partitions()
369 struct mtd_info *child, *master = mtd_get_master(mtd); in mtd_del_partition() local
370 int ret = -EINVAL; in mtd_del_partition()
372 mutex_lock(&master->master.partitions_lock); in mtd_del_partition()
373 list_for_each_entry(child, &mtd->partitions, part.node) { in mtd_del_partition()
374 if (child->index == partno) { in mtd_del_partition()
375 ret = __mtd_del_partition(child); in mtd_del_partition()
379 mutex_unlock(&master->master.partitions_lock); in mtd_del_partition()
387 * and registers the child MTD objects which are bound to the parent according
398 struct mtd_info *child, *master = mtd_get_master(parent); in add_mtd_partitions() local
403 nbparts, parent->name); in add_mtd_partitions()
406 child = allocate_partition(parent, parts + i, i, cur_offset); in add_mtd_partitions()
407 if (IS_ERR(child)) { in add_mtd_partitions()
408 ret = PTR_ERR(child); in add_mtd_partitions()
412 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
413 list_add_tail(&child->part.node, &parent->partitions); in add_mtd_partitions()
414 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
416 ret = add_mtd_device(child); in add_mtd_partitions()
418 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
419 list_del(&child->part.node); in add_mtd_partitions()
420 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
422 free_partition(child); in add_mtd_partitions()
426 mtd_add_partition_attrs(child); in add_mtd_partitions()
429 parse_mtd_partitions(child, parts[i].types, NULL); in add_mtd_partitions()
431 cur_offset = child->part.offset + child->part.size; in add_mtd_partitions()
452 if (!strcmp(p->name, name) && try_module_get(p->owner)) { in mtd_part_parser_get()
464 module_put(p->owner); in mtd_part_parser_put()
479 p->owner = owner; in __register_mtd_parser()
481 if (!p->cleanup) in __register_mtd_parser()
482 p->cleanup = &mtd_part_parser_cleanup_default; in __register_mtd_parser()
485 list_add(&p->list, &part_parsers); in __register_mtd_parser()
495 list_del(&p->list); in deregister_mtd_parser()
523 ret = (*parser->parse_fn)(master, &pparts->parts, data); in mtd_part_do_parse()
524 pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); in mtd_part_do_parse()
529 parser->name, master->name); in mtd_part_do_parse()
531 pparts->nr_parts = ret; in mtd_part_do_parse()
532 pparts->parser = parser; in mtd_part_do_parse()
538 * mtd_part_get_compatible_parser - find MTD parser by a compatible string
555 matches = p->of_match_table; in mtd_part_get_compatible_parser()
559 for (; matches->compatible[0]; matches++) { in mtd_part_get_compatible_parser()
560 if (!strcmp(matches->compatible, compat) && in mtd_part_get_compatible_parser()
561 try_module_get(p->owner)) { in mtd_part_get_compatible_parser()
581 struct device_node *child; in mtd_part_of_parse() local
585 const char *fixed = "fixed-partitions"; in mtd_part_of_parse()
588 dev = &master->dev; in mtd_part_of_parse()
591 dev = master->dev.parent; in mtd_part_of_parse()
604 for_each_child_of_node(np, child) in mtd_part_of_parse()
605 if (of_device_is_compatible(child, "nvmem-cells")) in mtd_part_of_parse()
606 of_node_set_flag(child, OF_POPULATED); in mtd_part_of_parse()
626 * For backward compatibility we have to try the "fixed-partitions" in mtd_part_of_parse()
628 * direct subnodes of a flash device DT node without any compatibility in mtd_part_of_parse()
647 * parse_mtd_partitions - parse and register MTD partitions
651 * @data: MTD partition parser-specific data
684 pr_debug("%s: parsing partitions %s\n", master->name, in parse_mtd_partitions()
689 pr_debug("%s: got parser %s\n", master->name, in parse_mtd_partitions()
690 parser ? parser->name : NULL); in parse_mtd_partitions()
721 parser = parts->parser; in mtd_part_parser_cleanup()
723 if (parser->cleanup) in mtd_part_parser_cleanup()
724 parser->cleanup(parts->parts, parts->nr_parts); in mtd_part_parser_cleanup()
735 return master->size; in mtd_get_device_size()