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>
30 kfree(mtd->name); in free_partition()
39 int wr_alignment = (parent->flags & MTD_NO_ERASE) ? in allocate_partition()
40 master->writesize : master->erasesize; in allocate_partition()
42 parent->part.size : parent->size; in allocate_partition()
43 struct mtd_info *child; in allocate_partition() local
49 child = kzalloc(sizeof(*child), GFP_KERNEL); in allocate_partition()
50 name = kstrdup(part->name, GFP_KERNEL); in allocate_partition()
51 if (!name || !child) { in allocate_partition()
53 parent->name); in allocate_partition()
55 kfree(child); in allocate_partition()
56 return ERR_PTR(-ENOMEM); in allocate_partition()
60 child->type = parent->type; in allocate_partition()
61 child->part.flags = parent->flags & ~part->mask_flags; in allocate_partition()
62 child->part.flags |= part->add_flags; in allocate_partition()
63 child->flags = child->part.flags; in allocate_partition()
64 child->part.size = part->size; in allocate_partition()
65 child->writesize = parent->writesize; in allocate_partition()
66 child->writebufsize = parent->writebufsize; in allocate_partition()
67 child->oobsize = parent->oobsize; in allocate_partition()
68 child->oobavail = parent->oobavail; in allocate_partition()
69 child->subpage_sft = parent->subpage_sft; in allocate_partition()
71 child->name = name; in allocate_partition()
72 child->owner = parent->owner; in allocate_partition()
76 * However, it is very useful to have the master node present, in allocate_partition()
82 child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? in allocate_partition()
83 &parent->dev : parent->dev.parent; in allocate_partition()
84 child->dev.of_node = part->of_node; in allocate_partition()
85 child->parent = parent; in allocate_partition()
86 child->part.offset = part->offset; in allocate_partition()
87 INIT_LIST_HEAD(&child->partitions); in allocate_partition()
89 if (child->part.offset == MTDPART_OFS_APPEND) in allocate_partition()
90 child->part.offset = cur_offset; in allocate_partition()
91 if (child->part.offset == MTDPART_OFS_NXTBLK) { in allocate_partition()
93 child->part.offset = cur_offset; in allocate_partition()
96 child->part.offset += wr_alignment - remainder; in allocate_partition()
98 "0x%012llx -> 0x%012llx\n", partno, in allocate_partition()
100 child->part.offset); in allocate_partition()
103 if (child->part.offset == MTDPART_OFS_RETAIN) { in allocate_partition()
104 child->part.offset = cur_offset; in allocate_partition()
105 if (parent_size - child->part.offset >= child->part.size) { in allocate_partition()
106 child->part.size = parent_size - child->part.offset - in allocate_partition()
107 child->part.size; in allocate_partition()
110 part->name, parent_size - child->part.offset, in allocate_partition()
111 child->part.size); in allocate_partition()
116 if (child->part.size == MTDPART_SIZ_FULL) in allocate_partition()
117 child->part.size = parent_size - child->part.offset; in allocate_partition()
119 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", in allocate_partition()
120 child->part.offset, child->part.offset + child->part.size, in allocate_partition()
121 child->name); in allocate_partition()
124 if (child->part.offset >= parent_size) { in allocate_partition()
126 child->part.offset = 0; in allocate_partition()
127 child->part.size = 0; in allocate_partition()
129 /* Initialize ->erasesize to make add_mtd_device() happy. */ in allocate_partition()
130 child->erasesize = parent->erasesize; in allocate_partition()
131 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", in allocate_partition()
132 part->name); in allocate_partition()
135 if (child->part.offset + child->part.size > parent->size) { in allocate_partition()
136 child->part.size = parent_size - child->part.offset; in allocate_partition()
137 …printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncate… in allocate_partition()
138 part->name, parent->name, child->part.size); in allocate_partition()
141 if (parent->numeraseregions > 1) { in allocate_partition()
143 int i, max = parent->numeraseregions; in allocate_partition()
144 u64 end = child->part.offset + child->part.size; in allocate_partition()
145 struct mtd_erase_region_info *regions = parent->eraseregions; in allocate_partition()
149 for (i = 0; i < max && regions[i].offset <= child->part.offset; in allocate_partition()
154 i--; in allocate_partition()
158 if (child->erasesize < regions[i].erasesize) in allocate_partition()
159 child->erasesize = regions[i].erasesize; in allocate_partition()
161 BUG_ON(child->erasesize == 0); in allocate_partition()
164 child->erasesize = master->erasesize; in allocate_partition()
168 * Child erasesize might differ from the parent one if the parent in allocate_partition()
172 if (!(child->flags & MTD_NO_ERASE)) in allocate_partition()
173 wr_alignment = child->erasesize; in allocate_partition()
175 tmp = mtd_get_master_ofs(child, 0); in allocate_partition()
177 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
181 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
182 …WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n", in allocate_partition()
183 part->name); in allocate_partition()
186 tmp = mtd_get_master_ofs(child, 0) + child->part.size; in allocate_partition()
188 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
189 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
190 …printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n… in allocate_partition()
191 part->name); in allocate_partition()
194 child->size = child->part.size; in allocate_partition()
195 child->ecc_step_size = parent->ecc_step_size; in allocate_partition()
196 child->ecc_strength = parent->ecc_strength; in allocate_partition()
197 child->bitflip_threshold = parent->bitflip_threshold; in allocate_partition()
199 if (master->_block_isbad) { in allocate_partition()
202 while (offs < child->part.size) { in allocate_partition()
203 if (mtd_block_isreserved(child, offs)) in allocate_partition()
204 child->ecc_stats.bbtblocks++; in allocate_partition()
205 else if (mtd_block_isbad(child, offs)) in allocate_partition()
206 child->ecc_stats.badblocks++; in allocate_partition()
207 offs += child->erasesize; in allocate_partition()
212 return child; in allocate_partition()
220 return sysfs_emit(buf, "%lld\n", mtd->part.offset); in offset_show()
231 int ret = sysfs_create_files(&new->dev.kobj, mtd_partition_attrs); in mtd_add_partition_attrs()
243 parent->part.size : parent->size; in mtd_add_partition()
245 struct mtd_info *child; in mtd_add_partition() local
251 return -EINVAL; in mtd_add_partition()
254 length = parent_size - offset; in mtd_add_partition()
257 return -EINVAL; in mtd_add_partition()
264 child = allocate_partition(parent, &part, -1, offset); in mtd_add_partition()
265 if (IS_ERR(child)) in mtd_add_partition()
266 return PTR_ERR(child); in mtd_add_partition()
268 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
269 list_add_tail(&child->part.node, &parent->partitions); in mtd_add_partition()
270 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
272 ret = add_mtd_device(child); in mtd_add_partition()
276 mtd_add_partition_attrs(child); in mtd_add_partition()
281 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
282 list_del(&child->part.node); in mtd_add_partition()
283 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
285 free_partition(child); in mtd_add_partition()
292 * __mtd_del_partition - delete MTD partition
300 struct mtd_info *child, *next; in __mtd_del_partition() local
303 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __mtd_del_partition()
304 err = __mtd_del_partition(child); in __mtd_del_partition()
309 sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs); in __mtd_del_partition()
315 list_del(&child->part.node); in __mtd_del_partition()
327 struct mtd_info *child, *next; in __del_mtd_partitions() local
331 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __del_mtd_partitions()
332 if (mtd_has_partitions(child)) in __del_mtd_partitions()
333 __del_mtd_partitions(child); in __del_mtd_partitions()
335 pr_info("Deleting %s MTD partition\n", child->name); in __del_mtd_partitions()
336 ret = del_mtd_device(child); in __del_mtd_partitions()
339 child->name, ret); in __del_mtd_partitions()
344 list_del(&child->part.node); in __del_mtd_partitions()
345 free_partition(child); in __del_mtd_partitions()
356 pr_info("Deleting MTD partitions on \"%s\":\n", mtd->name); in del_mtd_partitions()
358 mutex_lock(&master->master.partitions_lock); in del_mtd_partitions()
360 mutex_unlock(&master->master.partitions_lock); in del_mtd_partitions()
367 struct mtd_info *child, *master = mtd_get_master(mtd); in mtd_del_partition() local
368 int ret = -EINVAL; in mtd_del_partition()
370 mutex_lock(&master->master.partitions_lock); in mtd_del_partition()
371 list_for_each_entry(child, &mtd->partitions, part.node) { in mtd_del_partition()
372 if (child->index == partno) { in mtd_del_partition()
373 ret = __mtd_del_partition(child); in mtd_del_partition()
377 mutex_unlock(&master->master.partitions_lock); in mtd_del_partition()
385 * and registers the child MTD objects which are bound to the parent according
396 struct mtd_info *child, *master = mtd_get_master(parent); in add_mtd_partitions() local
401 nbparts, parent->name); in add_mtd_partitions()
404 child = allocate_partition(parent, parts + i, i, cur_offset); in add_mtd_partitions()
405 if (IS_ERR(child)) { in add_mtd_partitions()
406 ret = PTR_ERR(child); in add_mtd_partitions()
410 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
411 list_add_tail(&child->part.node, &parent->partitions); in add_mtd_partitions()
412 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
414 ret = add_mtd_device(child); in add_mtd_partitions()
416 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
417 list_del(&child->part.node); in add_mtd_partitions()
418 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
420 free_partition(child); in add_mtd_partitions()
424 mtd_add_partition_attrs(child); in add_mtd_partitions()
427 parse_mtd_partitions(child, parts[i].types, NULL); in add_mtd_partitions()
429 cur_offset = child->part.offset + child->part.size; in add_mtd_partitions()
450 if (!strcmp(p->name, name) && try_module_get(p->owner)) { in mtd_part_parser_get()
462 module_put(p->owner); in mtd_part_parser_put()
477 p->owner = owner; in __register_mtd_parser()
479 if (!p->cleanup) in __register_mtd_parser()
480 p->cleanup = &mtd_part_parser_cleanup_default; in __register_mtd_parser()
483 list_add(&p->list, &part_parsers); in __register_mtd_parser()
493 list_del(&p->list); in deregister_mtd_parser()
521 ret = (*parser->parse_fn)(master, &pparts->parts, data); in mtd_part_do_parse()
522 pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); in mtd_part_do_parse()
527 parser->name, master->name); in mtd_part_do_parse()
529 pparts->nr_parts = ret; in mtd_part_do_parse()
530 pparts->parser = parser; in mtd_part_do_parse()
536 * mtd_part_get_compatible_parser - find MTD parser by a compatible string
553 matches = p->of_match_table; in mtd_part_get_compatible_parser()
557 for (; matches->compatible[0]; matches++) { in mtd_part_get_compatible_parser()
558 if (!strcmp(matches->compatible, compat) && in mtd_part_get_compatible_parser()
559 try_module_get(p->owner)) { in mtd_part_get_compatible_parser()
581 const char *fixed = "fixed-partitions"; in mtd_part_of_parse()
606 * For backward compatibility we have to try the "fixed-partitions" in mtd_part_of_parse()
608 * direct subnodes of a flash device DT node without any compatibility in mtd_part_of_parse()
627 * parse_mtd_partitions - parse and register MTD partitions
631 * @data: MTD partition parser-specific data
664 pr_debug("%s: parsing partitions %s\n", master->name, in parse_mtd_partitions()
669 pr_debug("%s: got parser %s\n", master->name, in parse_mtd_partitions()
670 parser ? parser->name : NULL); in parse_mtd_partitions()
701 parser = parts->parser; in mtd_part_parser_cleanup()
703 if (parser->cleanup) in mtd_part_parser_cleanup()
704 parser->cleanup(parts->parts, parts->nr_parts); in mtd_part_parser_cleanup()
715 return master->size; in mtd_get_device_size()