x86: cdev lock_kernel() pushdown
[linux-2.6/zen-sources.git] / drivers / mtd / mtdconcat.c
blobd563dcd4b2644e2330398909e02f8e8146dbca9a
1 /*
2 * MTD device concatenation layer
4 * (C) 2002 Robert Kaiser <rkaiser@sysgo.de>
6 * NAND support by Christian Gan <cgan@iders.ca>
8 * This code is GPL
10 * $Id: mtdconcat.c,v 1.11 2005/11/07 11:14:20 gleixner Exp $
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
17 #include <linux/types.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/concat.h>
22 #include <asm/div64.h>
25 * Our storage structure:
26 * Subdev points to an array of pointers to struct mtd_info objects
27 * which is allocated along with this structure
30 struct mtd_concat {
31 struct mtd_info mtd;
32 int num_subdev;
33 struct mtd_info **subdev;
37 * how to calculate the size required for the above structure,
38 * including the pointer array subdev points to:
40 #define SIZEOF_STRUCT_MTD_CONCAT(num_subdev) \
41 ((sizeof(struct mtd_concat) + (num_subdev) * sizeof(struct mtd_info *)))
44 * Given a pointer to the MTD object in the mtd_concat structure,
45 * we can retrieve the pointer to that structure with this macro.
47 #define CONCAT(x) ((struct mtd_concat *)(x))
50 * MTD methods which look up the relevant subdevice, translate the
51 * effective address and pass through to the subdevice.
54 static int
55 concat_read(struct mtd_info *mtd, loff_t from, size_t len,
56 size_t * retlen, u_char * buf)
58 struct mtd_concat *concat = CONCAT(mtd);
59 int ret = 0, err;
60 int i;
62 *retlen = 0;
64 for (i = 0; i < concat->num_subdev; i++) {
65 struct mtd_info *subdev = concat->subdev[i];
66 size_t size, retsize;
68 if (from >= subdev->size) {
69 /* Not destined for this subdev */
70 size = 0;
71 from -= subdev->size;
72 continue;
74 if (from + len > subdev->size)
75 /* First part goes into this subdev */
76 size = subdev->size - from;
77 else
78 /* Entire transaction goes into this subdev */
79 size = len;
81 err = subdev->read(subdev, from, size, &retsize, buf);
83 /* Save information about bitflips! */
84 if (unlikely(err)) {
85 if (err == -EBADMSG) {
86 mtd->ecc_stats.failed++;
87 ret = err;
88 } else if (err == -EUCLEAN) {
89 mtd->ecc_stats.corrected++;
90 /* Do not overwrite -EBADMSG !! */
91 if (!ret)
92 ret = err;
93 } else
94 return err;
97 *retlen += retsize;
98 len -= size;
99 if (len == 0)
100 return ret;
102 buf += size;
103 from = 0;
105 return -EINVAL;
108 static int
109 concat_write(struct mtd_info *mtd, loff_t to, size_t len,
110 size_t * retlen, const u_char * buf)
112 struct mtd_concat *concat = CONCAT(mtd);
113 int err = -EINVAL;
114 int i;
116 if (!(mtd->flags & MTD_WRITEABLE))
117 return -EROFS;
119 *retlen = 0;
121 for (i = 0; i < concat->num_subdev; i++) {
122 struct mtd_info *subdev = concat->subdev[i];
123 size_t size, retsize;
125 if (to >= subdev->size) {
126 size = 0;
127 to -= subdev->size;
128 continue;
130 if (to + len > subdev->size)
131 size = subdev->size - to;
132 else
133 size = len;
135 if (!(subdev->flags & MTD_WRITEABLE))
136 err = -EROFS;
137 else
138 err = subdev->write(subdev, to, size, &retsize, buf);
140 if (err)
141 break;
143 *retlen += retsize;
144 len -= size;
145 if (len == 0)
146 break;
148 err = -EINVAL;
149 buf += size;
150 to = 0;
152 return err;
155 static int
156 concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
157 unsigned long count, loff_t to, size_t * retlen)
159 struct mtd_concat *concat = CONCAT(mtd);
160 struct kvec *vecs_copy;
161 unsigned long entry_low, entry_high;
162 size_t total_len = 0;
163 int i;
164 int err = -EINVAL;
166 if (!(mtd->flags & MTD_WRITEABLE))
167 return -EROFS;
169 *retlen = 0;
171 /* Calculate total length of data */
172 for (i = 0; i < count; i++)
173 total_len += vecs[i].iov_len;
175 /* Do not allow write past end of device */
176 if ((to + total_len) > mtd->size)
177 return -EINVAL;
179 /* Check alignment */
180 if (mtd->writesize > 1) {
181 uint64_t __to = to;
182 if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize))
183 return -EINVAL;
186 /* make a copy of vecs */
187 vecs_copy = kmalloc(sizeof(struct kvec) * count, GFP_KERNEL);
188 if (!vecs_copy)
189 return -ENOMEM;
190 memcpy(vecs_copy, vecs, sizeof(struct kvec) * count);
192 entry_low = 0;
193 for (i = 0; i < concat->num_subdev; i++) {
194 struct mtd_info *subdev = concat->subdev[i];
195 size_t size, wsize, retsize, old_iov_len;
197 if (to >= subdev->size) {
198 to -= subdev->size;
199 continue;
202 size = min(total_len, (size_t)(subdev->size - to));
203 wsize = size; /* store for future use */
205 entry_high = entry_low;
206 while (entry_high < count) {
207 if (size <= vecs_copy[entry_high].iov_len)
208 break;
209 size -= vecs_copy[entry_high++].iov_len;
212 old_iov_len = vecs_copy[entry_high].iov_len;
213 vecs_copy[entry_high].iov_len = size;
215 if (!(subdev->flags & MTD_WRITEABLE))
216 err = -EROFS;
217 else
218 err = subdev->writev(subdev, &vecs_copy[entry_low],
219 entry_high - entry_low + 1, to, &retsize);
221 vecs_copy[entry_high].iov_len = old_iov_len - size;
222 vecs_copy[entry_high].iov_base += size;
224 entry_low = entry_high;
226 if (err)
227 break;
229 *retlen += retsize;
230 total_len -= wsize;
232 if (total_len == 0)
233 break;
235 err = -EINVAL;
236 to = 0;
239 kfree(vecs_copy);
240 return err;
243 static int
244 concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
246 struct mtd_concat *concat = CONCAT(mtd);
247 struct mtd_oob_ops devops = *ops;
248 int i, err, ret = 0;
250 ops->retlen = ops->oobretlen = 0;
252 for (i = 0; i < concat->num_subdev; i++) {
253 struct mtd_info *subdev = concat->subdev[i];
255 if (from >= subdev->size) {
256 from -= subdev->size;
257 continue;
260 /* partial read ? */
261 if (from + devops.len > subdev->size)
262 devops.len = subdev->size - from;
264 err = subdev->read_oob(subdev, from, &devops);
265 ops->retlen += devops.retlen;
266 ops->oobretlen += devops.oobretlen;
268 /* Save information about bitflips! */
269 if (unlikely(err)) {
270 if (err == -EBADMSG) {
271 mtd->ecc_stats.failed++;
272 ret = err;
273 } else if (err == -EUCLEAN) {
274 mtd->ecc_stats.corrected++;
275 /* Do not overwrite -EBADMSG !! */
276 if (!ret)
277 ret = err;
278 } else
279 return err;
282 if (devops.datbuf) {
283 devops.len = ops->len - ops->retlen;
284 if (!devops.len)
285 return ret;
286 devops.datbuf += devops.retlen;
288 if (devops.oobbuf) {
289 devops.ooblen = ops->ooblen - ops->oobretlen;
290 if (!devops.ooblen)
291 return ret;
292 devops.oobbuf += ops->oobretlen;
295 from = 0;
297 return -EINVAL;
300 static int
301 concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
303 struct mtd_concat *concat = CONCAT(mtd);
304 struct mtd_oob_ops devops = *ops;
305 int i, err;
307 if (!(mtd->flags & MTD_WRITEABLE))
308 return -EROFS;
310 ops->retlen = 0;
312 for (i = 0; i < concat->num_subdev; i++) {
313 struct mtd_info *subdev = concat->subdev[i];
315 if (to >= subdev->size) {
316 to -= subdev->size;
317 continue;
320 /* partial write ? */
321 if (to + devops.len > subdev->size)
322 devops.len = subdev->size - to;
324 err = subdev->write_oob(subdev, to, &devops);
325 ops->retlen += devops.retlen;
326 if (err)
327 return err;
329 if (devops.datbuf) {
330 devops.len = ops->len - ops->retlen;
331 if (!devops.len)
332 return 0;
333 devops.datbuf += devops.retlen;
335 if (devops.oobbuf) {
336 devops.ooblen = ops->ooblen - ops->oobretlen;
337 if (!devops.ooblen)
338 return 0;
339 devops.oobbuf += devops.oobretlen;
341 to = 0;
343 return -EINVAL;
346 static void concat_erase_callback(struct erase_info *instr)
348 wake_up((wait_queue_head_t *) instr->priv);
351 static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
353 int err;
354 wait_queue_head_t waitq;
355 DECLARE_WAITQUEUE(wait, current);
358 * This code was stol^H^H^H^Hinspired by mtdchar.c
360 init_waitqueue_head(&waitq);
362 erase->mtd = mtd;
363 erase->callback = concat_erase_callback;
364 erase->priv = (unsigned long) &waitq;
367 * FIXME: Allow INTERRUPTIBLE. Which means
368 * not having the wait_queue head on the stack.
370 err = mtd->erase(mtd, erase);
371 if (!err) {
372 set_current_state(TASK_UNINTERRUPTIBLE);
373 add_wait_queue(&waitq, &wait);
374 if (erase->state != MTD_ERASE_DONE
375 && erase->state != MTD_ERASE_FAILED)
376 schedule();
377 remove_wait_queue(&waitq, &wait);
378 set_current_state(TASK_RUNNING);
380 err = (erase->state == MTD_ERASE_FAILED) ? -EIO : 0;
382 return err;
385 static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
387 struct mtd_concat *concat = CONCAT(mtd);
388 struct mtd_info *subdev;
389 int i, err;
390 u_int32_t length, offset = 0;
391 struct erase_info *erase;
393 if (!(mtd->flags & MTD_WRITEABLE))
394 return -EROFS;
396 if (instr->addr > concat->mtd.size)
397 return -EINVAL;
399 if (instr->len + instr->addr > concat->mtd.size)
400 return -EINVAL;
403 * Check for proper erase block alignment of the to-be-erased area.
404 * It is easier to do this based on the super device's erase
405 * region info rather than looking at each particular sub-device
406 * in turn.
408 if (!concat->mtd.numeraseregions) {
409 /* the easy case: device has uniform erase block size */
410 if (instr->addr & (concat->mtd.erasesize - 1))
411 return -EINVAL;
412 if (instr->len & (concat->mtd.erasesize - 1))
413 return -EINVAL;
414 } else {
415 /* device has variable erase size */
416 struct mtd_erase_region_info *erase_regions =
417 concat->mtd.eraseregions;
420 * Find the erase region where the to-be-erased area begins:
422 for (i = 0; i < concat->mtd.numeraseregions &&
423 instr->addr >= erase_regions[i].offset; i++) ;
424 --i;
427 * Now erase_regions[i] is the region in which the
428 * to-be-erased area begins. Verify that the starting
429 * offset is aligned to this region's erase size:
431 if (instr->addr & (erase_regions[i].erasesize - 1))
432 return -EINVAL;
435 * now find the erase region where the to-be-erased area ends:
437 for (; i < concat->mtd.numeraseregions &&
438 (instr->addr + instr->len) >= erase_regions[i].offset;
439 ++i) ;
440 --i;
442 * check if the ending offset is aligned to this region's erase size
444 if ((instr->addr + instr->len) & (erase_regions[i].erasesize -
446 return -EINVAL;
449 instr->fail_addr = 0xffffffff;
451 /* make a local copy of instr to avoid modifying the caller's struct */
452 erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL);
454 if (!erase)
455 return -ENOMEM;
457 *erase = *instr;
458 length = instr->len;
461 * find the subdevice where the to-be-erased area begins, adjust
462 * starting offset to be relative to the subdevice start
464 for (i = 0; i < concat->num_subdev; i++) {
465 subdev = concat->subdev[i];
466 if (subdev->size <= erase->addr) {
467 erase->addr -= subdev->size;
468 offset += subdev->size;
469 } else {
470 break;
474 /* must never happen since size limit has been verified above */
475 BUG_ON(i >= concat->num_subdev);
477 /* now do the erase: */
478 err = 0;
479 for (; length > 0; i++) {
480 /* loop for all subdevices affected by this request */
481 subdev = concat->subdev[i]; /* get current subdevice */
483 /* limit length to subdevice's size: */
484 if (erase->addr + length > subdev->size)
485 erase->len = subdev->size - erase->addr;
486 else
487 erase->len = length;
489 if (!(subdev->flags & MTD_WRITEABLE)) {
490 err = -EROFS;
491 break;
493 length -= erase->len;
494 if ((err = concat_dev_erase(subdev, erase))) {
495 /* sanity check: should never happen since
496 * block alignment has been checked above */
497 BUG_ON(err == -EINVAL);
498 if (erase->fail_addr != 0xffffffff)
499 instr->fail_addr = erase->fail_addr + offset;
500 break;
503 * erase->addr specifies the offset of the area to be
504 * erased *within the current subdevice*. It can be
505 * non-zero only the first time through this loop, i.e.
506 * for the first subdevice where blocks need to be erased.
507 * All the following erases must begin at the start of the
508 * current subdevice, i.e. at offset zero.
510 erase->addr = 0;
511 offset += subdev->size;
513 instr->state = erase->state;
514 kfree(erase);
515 if (err)
516 return err;
518 if (instr->callback)
519 instr->callback(instr);
520 return 0;
523 static int concat_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
525 struct mtd_concat *concat = CONCAT(mtd);
526 int i, err = -EINVAL;
528 if ((len + ofs) > mtd->size)
529 return -EINVAL;
531 for (i = 0; i < concat->num_subdev; i++) {
532 struct mtd_info *subdev = concat->subdev[i];
533 size_t size;
535 if (ofs >= subdev->size) {
536 size = 0;
537 ofs -= subdev->size;
538 continue;
540 if (ofs + len > subdev->size)
541 size = subdev->size - ofs;
542 else
543 size = len;
545 err = subdev->lock(subdev, ofs, size);
547 if (err)
548 break;
550 len -= size;
551 if (len == 0)
552 break;
554 err = -EINVAL;
555 ofs = 0;
558 return err;
561 static int concat_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
563 struct mtd_concat *concat = CONCAT(mtd);
564 int i, err = 0;
566 if ((len + ofs) > mtd->size)
567 return -EINVAL;
569 for (i = 0; i < concat->num_subdev; i++) {
570 struct mtd_info *subdev = concat->subdev[i];
571 size_t size;
573 if (ofs >= subdev->size) {
574 size = 0;
575 ofs -= subdev->size;
576 continue;
578 if (ofs + len > subdev->size)
579 size = subdev->size - ofs;
580 else
581 size = len;
583 err = subdev->unlock(subdev, ofs, size);
585 if (err)
586 break;
588 len -= size;
589 if (len == 0)
590 break;
592 err = -EINVAL;
593 ofs = 0;
596 return err;
599 static void concat_sync(struct mtd_info *mtd)
601 struct mtd_concat *concat = CONCAT(mtd);
602 int i;
604 for (i = 0; i < concat->num_subdev; i++) {
605 struct mtd_info *subdev = concat->subdev[i];
606 subdev->sync(subdev);
610 static int concat_suspend(struct mtd_info *mtd)
612 struct mtd_concat *concat = CONCAT(mtd);
613 int i, rc = 0;
615 for (i = 0; i < concat->num_subdev; i++) {
616 struct mtd_info *subdev = concat->subdev[i];
617 if ((rc = subdev->suspend(subdev)) < 0)
618 return rc;
620 return rc;
623 static void concat_resume(struct mtd_info *mtd)
625 struct mtd_concat *concat = CONCAT(mtd);
626 int i;
628 for (i = 0; i < concat->num_subdev; i++) {
629 struct mtd_info *subdev = concat->subdev[i];
630 subdev->resume(subdev);
634 static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
636 struct mtd_concat *concat = CONCAT(mtd);
637 int i, res = 0;
639 if (!concat->subdev[0]->block_isbad)
640 return res;
642 if (ofs > mtd->size)
643 return -EINVAL;
645 for (i = 0; i < concat->num_subdev; i++) {
646 struct mtd_info *subdev = concat->subdev[i];
648 if (ofs >= subdev->size) {
649 ofs -= subdev->size;
650 continue;
653 res = subdev->block_isbad(subdev, ofs);
654 break;
657 return res;
660 static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
662 struct mtd_concat *concat = CONCAT(mtd);
663 int i, err = -EINVAL;
665 if (!concat->subdev[0]->block_markbad)
666 return 0;
668 if (ofs > mtd->size)
669 return -EINVAL;
671 for (i = 0; i < concat->num_subdev; i++) {
672 struct mtd_info *subdev = concat->subdev[i];
674 if (ofs >= subdev->size) {
675 ofs -= subdev->size;
676 continue;
679 err = subdev->block_markbad(subdev, ofs);
680 if (!err)
681 mtd->ecc_stats.badblocks++;
682 break;
685 return err;
689 * This function constructs a virtual MTD device by concatenating
690 * num_devs MTD devices. A pointer to the new device object is
691 * stored to *new_dev upon success. This function does _not_
692 * register any devices: this is the caller's responsibility.
694 struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to concatenate */
695 int num_devs, /* number of subdevices */
696 char *name)
697 { /* name for the new device */
698 int i;
699 size_t size;
700 struct mtd_concat *concat;
701 u_int32_t max_erasesize, curr_erasesize;
702 int num_erase_region;
704 printk(KERN_NOTICE "Concatenating MTD devices:\n");
705 for (i = 0; i < num_devs; i++)
706 printk(KERN_NOTICE "(%d): \"%s\"\n", i, subdev[i]->name);
707 printk(KERN_NOTICE "into device \"%s\"\n", name);
709 /* allocate the device structure */
710 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
711 concat = kzalloc(size, GFP_KERNEL);
712 if (!concat) {
713 printk
714 ("memory allocation error while creating concatenated device \"%s\"\n",
715 name);
716 return NULL;
718 concat->subdev = (struct mtd_info **) (concat + 1);
721 * Set up the new "super" device's MTD object structure, check for
722 * incompatibilites between the subdevices.
724 concat->mtd.type = subdev[0]->type;
725 concat->mtd.flags = subdev[0]->flags;
726 concat->mtd.size = subdev[0]->size;
727 concat->mtd.erasesize = subdev[0]->erasesize;
728 concat->mtd.writesize = subdev[0]->writesize;
729 concat->mtd.subpage_sft = subdev[0]->subpage_sft;
730 concat->mtd.oobsize = subdev[0]->oobsize;
731 concat->mtd.oobavail = subdev[0]->oobavail;
732 if (subdev[0]->writev)
733 concat->mtd.writev = concat_writev;
734 if (subdev[0]->read_oob)
735 concat->mtd.read_oob = concat_read_oob;
736 if (subdev[0]->write_oob)
737 concat->mtd.write_oob = concat_write_oob;
738 if (subdev[0]->block_isbad)
739 concat->mtd.block_isbad = concat_block_isbad;
740 if (subdev[0]->block_markbad)
741 concat->mtd.block_markbad = concat_block_markbad;
743 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
745 concat->subdev[0] = subdev[0];
747 for (i = 1; i < num_devs; i++) {
748 if (concat->mtd.type != subdev[i]->type) {
749 kfree(concat);
750 printk("Incompatible device type on \"%s\"\n",
751 subdev[i]->name);
752 return NULL;
754 if (concat->mtd.flags != subdev[i]->flags) {
756 * Expect all flags except MTD_WRITEABLE to be
757 * equal on all subdevices.
759 if ((concat->mtd.flags ^ subdev[i]->
760 flags) & ~MTD_WRITEABLE) {
761 kfree(concat);
762 printk("Incompatible device flags on \"%s\"\n",
763 subdev[i]->name);
764 return NULL;
765 } else
766 /* if writeable attribute differs,
767 make super device writeable */
768 concat->mtd.flags |=
769 subdev[i]->flags & MTD_WRITEABLE;
771 concat->mtd.size += subdev[i]->size;
772 concat->mtd.ecc_stats.badblocks +=
773 subdev[i]->ecc_stats.badblocks;
774 if (concat->mtd.writesize != subdev[i]->writesize ||
775 concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
776 concat->mtd.oobsize != subdev[i]->oobsize ||
777 !concat->mtd.read_oob != !subdev[i]->read_oob ||
778 !concat->mtd.write_oob != !subdev[i]->write_oob) {
779 kfree(concat);
780 printk("Incompatible OOB or ECC data on \"%s\"\n",
781 subdev[i]->name);
782 return NULL;
784 concat->subdev[i] = subdev[i];
788 concat->mtd.ecclayout = subdev[0]->ecclayout;
790 concat->num_subdev = num_devs;
791 concat->mtd.name = name;
793 concat->mtd.erase = concat_erase;
794 concat->mtd.read = concat_read;
795 concat->mtd.write = concat_write;
796 concat->mtd.sync = concat_sync;
797 concat->mtd.lock = concat_lock;
798 concat->mtd.unlock = concat_unlock;
799 concat->mtd.suspend = concat_suspend;
800 concat->mtd.resume = concat_resume;
803 * Combine the erase block size info of the subdevices:
805 * first, walk the map of the new device and see how
806 * many changes in erase size we have
808 max_erasesize = curr_erasesize = subdev[0]->erasesize;
809 num_erase_region = 1;
810 for (i = 0; i < num_devs; i++) {
811 if (subdev[i]->numeraseregions == 0) {
812 /* current subdevice has uniform erase size */
813 if (subdev[i]->erasesize != curr_erasesize) {
814 /* if it differs from the last subdevice's erase size, count it */
815 ++num_erase_region;
816 curr_erasesize = subdev[i]->erasesize;
817 if (curr_erasesize > max_erasesize)
818 max_erasesize = curr_erasesize;
820 } else {
821 /* current subdevice has variable erase size */
822 int j;
823 for (j = 0; j < subdev[i]->numeraseregions; j++) {
825 /* walk the list of erase regions, count any changes */
826 if (subdev[i]->eraseregions[j].erasesize !=
827 curr_erasesize) {
828 ++num_erase_region;
829 curr_erasesize =
830 subdev[i]->eraseregions[j].
831 erasesize;
832 if (curr_erasesize > max_erasesize)
833 max_erasesize = curr_erasesize;
839 if (num_erase_region == 1) {
841 * All subdevices have the same uniform erase size.
842 * This is easy:
844 concat->mtd.erasesize = curr_erasesize;
845 concat->mtd.numeraseregions = 0;
846 } else {
848 * erase block size varies across the subdevices: allocate
849 * space to store the data describing the variable erase regions
851 struct mtd_erase_region_info *erase_region_p;
852 u_int32_t begin, position;
854 concat->mtd.erasesize = max_erasesize;
855 concat->mtd.numeraseregions = num_erase_region;
856 concat->mtd.eraseregions = erase_region_p =
857 kmalloc(num_erase_region *
858 sizeof (struct mtd_erase_region_info), GFP_KERNEL);
859 if (!erase_region_p) {
860 kfree(concat);
861 printk
862 ("memory allocation error while creating erase region list"
863 " for device \"%s\"\n", name);
864 return NULL;
868 * walk the map of the new device once more and fill in
869 * in erase region info:
871 curr_erasesize = subdev[0]->erasesize;
872 begin = position = 0;
873 for (i = 0; i < num_devs; i++) {
874 if (subdev[i]->numeraseregions == 0) {
875 /* current subdevice has uniform erase size */
876 if (subdev[i]->erasesize != curr_erasesize) {
878 * fill in an mtd_erase_region_info structure for the area
879 * we have walked so far:
881 erase_region_p->offset = begin;
882 erase_region_p->erasesize =
883 curr_erasesize;
884 erase_region_p->numblocks =
885 (position - begin) / curr_erasesize;
886 begin = position;
888 curr_erasesize = subdev[i]->erasesize;
889 ++erase_region_p;
891 position += subdev[i]->size;
892 } else {
893 /* current subdevice has variable erase size */
894 int j;
895 for (j = 0; j < subdev[i]->numeraseregions; j++) {
896 /* walk the list of erase regions, count any changes */
897 if (subdev[i]->eraseregions[j].
898 erasesize != curr_erasesize) {
899 erase_region_p->offset = begin;
900 erase_region_p->erasesize =
901 curr_erasesize;
902 erase_region_p->numblocks =
903 (position -
904 begin) / curr_erasesize;
905 begin = position;
907 curr_erasesize =
908 subdev[i]->eraseregions[j].
909 erasesize;
910 ++erase_region_p;
912 position +=
913 subdev[i]->eraseregions[j].
914 numblocks * curr_erasesize;
918 /* Now write the final entry */
919 erase_region_p->offset = begin;
920 erase_region_p->erasesize = curr_erasesize;
921 erase_region_p->numblocks = (position - begin) / curr_erasesize;
924 return &concat->mtd;
928 * This function destroys an MTD object obtained from concat_mtd_devs()
931 void mtd_concat_destroy(struct mtd_info *mtd)
933 struct mtd_concat *concat = CONCAT(mtd);
934 if (concat->mtd.numeraseregions)
935 kfree(concat->mtd.eraseregions);
936 kfree(concat);
939 EXPORT_SYMBOL(mtd_concat_create);
940 EXPORT_SYMBOL(mtd_concat_destroy);
942 MODULE_LICENSE("GPL");
943 MODULE_AUTHOR("Robert Kaiser <rkaiser@sysgo.de>");
944 MODULE_DESCRIPTION("Generic support for concatenating of MTD devices");