Release 4.7 drivers/mtd/mtdconcat.c
/*
* MTD device concatenation layer
*
* Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
* Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
*
* NAND support by Christian Gan <cgan@iders.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/backing-dev.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/concat.h>
#include <asm/div64.h>
/*
* Our storage structure:
* Subdev points to an array of pointers to struct mtd_info objects
* which is allocated along with this structure
*
*/
struct mtd_concat {
struct mtd_info mtd;
int num_subdev;
struct mtd_info **subdev;
};
/*
* how to calculate the size required for the above structure,
* including the pointer array subdev points to:
*/
#define SIZEOF_STRUCT_MTD_CONCAT(num_subdev) \
((sizeof(struct mtd_concat) + (num_subdev) * sizeof(struct mtd_info *)))
/*
* Given a pointer to the MTD object in the mtd_concat structure,
* we can retrieve the pointer to that structure with this macro.
*/
#define CONCAT(x) ((struct mtd_concat *)(x))
/*
* MTD methods which look up the relevant subdevice, translate the
* effective address and pass through to the subdevice.
*/
static int
concat_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t * retlen, u_char * buf)
{
struct mtd_concat *concat = CONCAT(mtd);
int ret = 0, err;
int i;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, retsize;
if (from >= subdev->size) {
/* Not destined for this subdev */
size = 0;
from -= subdev->size;
continue;
}
if (from + len > subdev->size)
/* First part goes into this subdev */
size = subdev->size - from;
else
/* Entire transaction goes into this subdev */
size = len;
err = mtd_read(subdev, from, size, &retsize, buf);
/* Save information about bitflips! */
if (unlikely(err)) {
if (mtd_is_eccerr(err)) {
mtd->ecc_stats.failed++;
ret = err;
} else if (mtd_is_bitflip(err)) {
mtd->ecc_stats.corrected++;
/* Do not overwrite -EBADMSG !! */
if (!ret)
ret = err;
} else
return err;
}
*retlen += retsize;
len -= size;
if (len == 0)
return ret;
buf += size;
from = 0;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 161 | 69.10% | 2 | 28.57% |
thomas gleixner | thomas gleixner | 64 | 27.47% | 2 | 28.57% |
brian norris | brian norris | 6 | 2.58% | 1 | 14.29% |
david woodhouse | david woodhouse | 1 | 0.43% | 1 | 14.29% |
artem bityutskiy | artem bityutskiy | 1 | 0.43% | 1 | 14.29% |
| Total | 233 | 100.00% | 7 | 100.00% |
static int
concat_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t * retlen, const u_char * buf)
{
struct mtd_concat *concat = CONCAT(mtd);
int err = -EINVAL;
int i;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, retsize;
if (to >= subdev->size) {
size = 0;
to -= subdev->size;
continue;
}
if (to + len > subdev->size)
size = subdev->size - to;
else
size = len;
err = mtd_write(subdev, to, size, &retsize, buf);
if (err)
break;
*retlen += retsize;
len -= size;
if (len == 0)
break;
err = -EINVAL;
buf += size;
to = 0;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 175 | 99.43% | 2 | 66.67% |
artem bityutskiy | artem bityutskiy | 1 | 0.57% | 1 | 33.33% |
| Total | 176 | 100.00% | 3 | 100.00% |
static int
concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
unsigned long count, loff_t to, size_t * retlen)
{
struct mtd_concat *concat = CONCAT(mtd);
struct kvec *vecs_copy;
unsigned long entry_low, entry_high;
size_t total_len = 0;
int i;
int err = -EINVAL;
/* Calculate total length of data */
for (i = 0; i < count; i++)
total_len += vecs[i].iov_len;
/* Check alignment */
if (mtd->writesize > 1) {
uint64_t __to = to;
if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize))
return -EINVAL;
}
/* make a copy of vecs */
vecs_copy = kmemdup(vecs, sizeof(struct kvec) * count, GFP_KERNEL);
if (!vecs_copy)
return -ENOMEM;
entry_low = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, wsize, retsize, old_iov_len;
if (to >= subdev->size) {
to -= subdev->size;
continue;
}
size = min_t(uint64_t, total_len, subdev->size - to);
wsize = size; /* store for future use */
entry_high = entry_low;
while (entry_high < count) {
if (size <= vecs_copy[entry_high].iov_len)
break;
size -= vecs_copy[entry_high++].iov_len;
}
old_iov_len = vecs_copy[entry_high].iov_len;
vecs_copy[entry_high].iov_len = size;
err = mtd_writev(subdev, &vecs_copy[entry_low],
entry_high - entry_low + 1, to, &retsize);
vecs_copy[entry_high].iov_len = old_iov_len - size;
vecs_copy[entry_high].iov_base += size;
entry_low = entry_high;
if (err)
break;
*retlen += retsize;
total_len -= wsize;
if (total_len == 0)
break;
err = -EINVAL;
to = 0;
}
kfree(vecs_copy);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alexander belyakov | alexander belyakov | 344 | 93.22% | 1 | 11.11% |
andrew morton | andrew morton | 11 | 2.98% | 1 | 11.11% |
adrian hunter | adrian hunter | 3 | 0.81% | 1 | 11.11% |
david woodhouse | david woodhouse | 3 | 0.81% | 2 | 22.22% |
joern engel | joern engel | 3 | 0.81% | 1 | 11.11% |
julia lawall | julia lawall | 3 | 0.81% | 1 | 11.11% |
thomas gleixner | thomas gleixner | 1 | 0.27% | 1 | 11.11% |
artem bityutskiy | artem bityutskiy | 1 | 0.27% | 1 | 11.11% |
| Total | 369 | 100.00% | 9 | 100.00% |
static int
concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
{
struct mtd_concat *concat = CONCAT(mtd);
struct mtd_oob_ops devops = *ops;
int i, err, ret = 0;
ops->retlen = ops->oobretlen = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if (from >= subdev->size) {
from -= subdev->size;
continue;
}
/* partial read ? */
if (from + devops.len > subdev->size)
devops.len = subdev->size - from;
err = mtd_read_oob(subdev, from, &devops);
ops->retlen += devops.retlen;
ops->oobretlen += devops.oobretlen;
/* Save information about bitflips! */
if (unlikely(err)) {
if (mtd_is_eccerr(err)) {
mtd->ecc_stats.failed++;
ret = err;
} else if (mtd_is_bitflip(err)) {
mtd->ecc_stats.corrected++;
/* Do not overwrite -EBADMSG !! */
if (!ret)
ret = err;
} else
return err;
}
if (devops.datbuf) {
devops.len = ops->len - ops->retlen;
if (!devops.len)
return ret;
devops.datbuf += devops.retlen;
}
if (devops.oobbuf) {
devops.ooblen = ops->ooblen - ops->oobretlen;
if (!devops.ooblen)
return ret;
devops.oobbuf += ops->oobretlen;
}
from = 0;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david woodhouse | david woodhouse | 123 | 41.41% | 1 | 12.50% |
thomas gleixner | thomas gleixner | 118 | 39.73% | 2 | 25.00% |
vitaly wool | vitaly wool | 46 | 15.49% | 1 | 12.50% |
brian norris | brian norris | 6 | 2.02% | 1 | 12.50% |
alexander belyakov | alexander belyakov | 2 | 0.67% | 1 | 12.50% |
russell king | russell king | 1 | 0.34% | 1 | 12.50% |
artem bityutskiy | artem bityutskiy | 1 | 0.34% | 1 | 12.50% |
| Total | 297 | 100.00% | 8 | 100.00% |
static int
concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
{
struct mtd_concat *concat = CONCAT(mtd);
struct mtd_oob_ops devops = *ops;
int i, err;
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
ops->retlen = ops->oobretlen = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if (to >= subdev->size) {
to -= subdev->size;
continue;
}
/* partial write ? */
if (to + devops.len > subdev->size)
devops.len = subdev->size - to;
err = mtd_write_oob(subdev, to, &devops);
ops->retlen += devops.retlen;
ops->oobretlen += devops.oobretlen;
if (err)
return err;
if (devops.datbuf) {
devops.len = ops->len - ops->retlen;
if (!devops.len)
return 0;
devops.datbuf += devops.retlen;
}
if (devops.oobbuf) {
devops.ooblen = ops->ooblen - ops->oobretlen;
if (!devops.ooblen)
return 0;
devops.oobbuf += devops.oobretlen;
}
to = 0;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david woodhouse | david woodhouse | 142 | 55.91% | 1 | 14.29% |
thomas gleixner | thomas gleixner | 64 | 25.20% | 1 | 14.29% |
vitaly wool | vitaly wool | 33 | 12.99% | 1 | 14.29% |
niklas cassel | niklas cassel | 8 | 3.15% | 1 | 14.29% |
felix radensky | felix radensky | 5 | 1.97% | 1 | 14.29% |
artem bityutskiy | artem bityutskiy | 1 | 0.39% | 1 | 14.29% |
russell king | russell king | 1 | 0.39% | 1 | 14.29% |
| Total | 254 | 100.00% | 7 | 100.00% |
static void concat_erase_callback(struct erase_info *instr)
{
wake_up((wait_queue_head_t *) instr->priv);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 22 | 100.00% | 1 | 100.00% |
| Total | 22 | 100.00% | 1 | 100.00% |
static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
{
int err;
wait_queue_head_t waitq;
DECLARE_WAITQUEUE(wait, current);
/*
* This code was stol^H^H^H^Hinspired by mtdchar.c
*/
init_waitqueue_head(&waitq);
erase->mtd = mtd;
erase->callback = concat_erase_callback;
erase->priv = (unsigned long) &waitq;
/*
* FIXME: Allow INTERRUPTIBLE. Which means
* not having the wait_queue head on the stack.
*/
err = mtd_erase(mtd, erase);
if (!err) {
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&waitq, &wait);
if (erase->state != MTD_ERASE_DONE
&& erase->state != MTD_ERASE_FAILED)
schedule();
remove_wait_queue(&waitq, &wait);
set_current_state(TASK_RUNNING);
err = (erase->state == MTD_ERASE_FAILED) ? -EIO : 0;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 138 | 99.28% | 1 | 50.00% |
artem bityutskiy | artem bityutskiy | 1 | 0.72% | 1 | 50.00% |
| Total | 139 | 100.00% | 2 | 100.00% |
static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
{
struct mtd_concat *concat = CONCAT(mtd);
struct mtd_info *subdev;
int i, err;
uint64_t length, offset = 0;
struct erase_info *erase;
/*
* Check for proper erase block alignment of the to-be-erased area.
* It is easier to do this based on the super device's erase
* region info rather than looking at each particular sub-device
* in turn.
*/
if (!concat->mtd.numeraseregions) {
/* the easy case: device has uniform erase block size */
if (instr->addr & (concat->mtd.erasesize - 1))
return -EINVAL;
if (instr->len & (concat->mtd.erasesize - 1))
return -EINVAL;
} else {
/* device has variable erase size */
struct mtd_erase_region_info *erase_regions =
concat->mtd.eraseregions;
/*
* Find the erase region where the to-be-erased area begins:
*/
for (i = 0; i < concat->mtd.numeraseregions &&
instr->addr >= erase_regions[i].offset; i++) ;
--i;
/*
* Now erase_regions[i] is the region in which the
* to-be-erased area begins. Verify that the starting
* offset is aligned to this region's erase size:
*/
if (i < 0 || instr->addr & (erase_regions[i].erasesize - 1))
return -EINVAL;
/*
* now find the erase region where the to-be-erased area ends:
*/
for (; i < concat->mtd.numeraseregions &&
(instr->addr + instr->len) >= erase_regions[i].offset;
++i) ;
--i;
/*
* check if the ending offset is aligned to this region's erase size
*/
if (i < 0 || ((instr->addr + instr->len) &
(erase_regions[i].erasesize - 1)))
return -EINVAL;
}
/* make a local copy of instr to avoid modifying the caller's struct */
erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL);
if (!erase)
return -ENOMEM;
*erase = *instr;
length = instr->len;
/*
* find the subdevice where the to-be-erased area begins, adjust
* starting offset to be relative to the subdevice start
*/
for (i = 0; i < concat->num_subdev; i++) {
subdev = concat->subdev[i];
if (subdev->size <= erase->addr) {
erase->addr -= subdev->size;
offset += subdev->size;
} else {
break;
}
}
/* must never happen since size limit has been verified above */
BUG_ON(i >= concat->num_subdev);
/* now do the erase: */
err = 0;
for (; length > 0; i++) {
/* loop for all subdevices affected by this request */
subdev = concat->subdev[i]; /* get current subdevice */
/* limit length to subdevice's size: */
if (erase->addr + length > subdev->size)
erase->len = subdev->size - erase->addr;
else
erase->len = length;
length -= erase->len;
if ((err = concat_dev_erase(subdev, erase))) {
/* sanity check: should never happen since
* block alignment has been checked above */
BUG_ON(err == -EINVAL);
if (erase->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
instr->fail_addr = erase->fail_addr + offset;
break;
}
/*
* erase->addr specifies the offset of the area to be
* erased *within the current subdevice*. It can be
* non-zero only the first time through this loop, i.e.
* for the first subdevice where blocks need to be erased.
* All the following erases must begin at the start of the
* current subdevice, i.e. at offset zero.
*/
erase->addr = 0;
offset += subdev->size;
}
instr->state = erase->state;
kfree(erase);
if (err)
return err;
if (instr->callback)
instr->callback(instr);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 442 | 87.52% | 2 | 28.57% |
david woodhouse | david woodhouse | 45 | 8.91% | 1 | 14.29% |
roel kluin | roel kluin | 10 | 1.98% | 1 | 14.29% |
eric sesterhenn | eric sesterhenn | 6 | 1.19% | 1 | 14.29% |
adrian hunter | adrian hunter | 2 | 0.40% | 2 | 28.57% |
| Total | 505 | 100.00% | 7 | 100.00% |
static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
struct mtd_concat *concat = CONCAT(mtd);
int i, err = -EINVAL;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
uint64_t size;
if (ofs >= subdev->size) {
size = 0;
ofs -= subdev->size;
continue;
}
if (ofs + len > subdev->size)
size = subdev->size - ofs;
else
size = len;
err = mtd_lock(subdev, ofs, size);
if (err)
break;
len -= size;
if (len == 0)
break;
err = -EINVAL;
ofs = 0;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 147 | 98.00% | 2 | 50.00% |
adrian hunter | adrian hunter | 2 | 1.33% | 1 | 25.00% |
artem bityutskiy | artem bityutskiy | 1 | 0.67% | 1 | 25.00% |
| Total | 150 | 100.00% | 4 | 100.00% |
static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
struct mtd_concat *concat = CONCAT(mtd);
int i, err = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
uint64_t size;
if (ofs >= subdev->size) {
size = 0;
ofs -= subdev->size;
continue;
}
if (ofs + len > subdev->size)
size = subdev->size - ofs;
else
size = len;
err = mtd_unlock(subdev, ofs, size);
if (err)
break;
len -= size;
if (len == 0)
break;
err = -EINVAL;
ofs = 0;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 108 | 72.48% | 2 | 40.00% |
alexander belyakov | alexander belyakov | 38 | 25.50% | 1 | 20.00% |
adrian hunter | adrian hunter | 2 | 1.34% | 1 | 20.00% |
artem bityutskiy | artem bityutskiy | 1 | 0.67% | 1 | 20.00% |
| Total | 149 | 100.00% | 5 | 100.00% |
static void concat_sync(struct mtd_info *mtd)
{
struct mtd_concat *concat = CONCAT(mtd);
int i;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
mtd_sync(subdev);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alexander belyakov | alexander belyakov | 57 | 98.28% | 1 | 50.00% |
artem bityutskiy | artem bityutskiy | 1 | 1.72% | 1 | 50.00% |
| Total | 58 | 100.00% | 2 | 100.00% |
static int concat_suspend(struct mtd_info *mtd)
{
struct mtd_concat *concat = CONCAT(mtd);
int i, rc = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if ((rc = mtd_suspend(subdev)) < 0)
return rc;
}
return rc;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alexander belyakov | alexander belyakov | 66 | 86.84% | 1 | 33.33% |
russell king | russell king | 9 | 11.84% | 1 | 33.33% |
artem bityutskiy | artem bityutskiy | 1 | 1.32% | 1 | 33.33% |
| Total | 76 | 100.00% | 3 | 100.00% |
static void concat_resume(struct mtd_info *mtd)
{
struct mtd_concat *concat = CONCAT(mtd);
int i;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
mtd_resume(subdev);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 56 | 96.55% | 1 | 33.33% |
artem bityutskiy | artem bityutskiy | 1 | 1.72% | 1 | 33.33% |
alexander belyakov | alexander belyakov | 1 | 1.72% | 1 | 33.33% |
| Total | 58 | 100.00% | 3 | 100.00% |
static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
{
struct mtd_concat *concat = CONCAT(mtd);
int i, res = 0;
if (!mtd_can_have_bb(concat->subdev[0]))
return res;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if (ofs >= subdev->size) {
ofs -= subdev->size;
continue;
}
res = mtd_block_isbad(subdev, ofs);
break;
}
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 63 | 59.43% | 1 | 25.00% |
alexander belyakov | alexander belyakov | 39 | 36.79% | 1 | 25.00% |
artem bityutskiy | artem bityutskiy | 4 | 3.77% | 2 | 50.00% |
| Total | 106 | 100.00% | 4 | 100.00% |
static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
{
struct mtd_concat *concat = CONCAT(mtd);
int i, err = -EINVAL;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if (ofs >= subdev->size) {
ofs -= subdev->size;
continue;
}
err = mtd_block_markbad(subdev, ofs);
if (!err)
mtd->ecc_stats.badblocks++;
break;
}
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 57 | 55.34% | 1 | 25.00% |
alexander belyakov | alexander belyakov | 33 | 32.04% | 1 | 25.00% |
thomas gleixner | thomas gleixner | 12 | 11.65% | 1 | 25.00% |
artem bityutskiy | artem bityutskiy | 1 | 0.97% | 1 | 25.00% |
| Total | 103 | 100.00% | 4 | 100.00% |
/*
* try to support NOMMU mmaps on concatenated devices
* - we don't support subdev spanning as we can't guarantee it'll work
*/
static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,
unsigned long len,
unsigned long offset,
unsigned long flags)
{
struct mtd_concat *concat = CONCAT(mtd);
int i;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
if (offset >= subdev->size) {
offset -= subdev->size;
continue;
}
return mtd_get_unmapped_area(subdev, len, offset, flags);
}
return (unsigned long) -ENOSYS;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david howells | david howells | 102 | 99.03% | 1 | 50.00% |
artem bityutskiy | artem bityutskiy | 1 | 0.97% | 1 | 50.00% |
| Total | 103 | 100.00% | 2 | 100.00% |
/*
* This function constructs a virtual MTD device by concatenating
* num_devs MTD devices. A pointer to the new device object is
* stored to *new_dev upon success. This function does _not_
* register any devices: this is the caller's responsibility.
*/
struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to concatenate */
int num_devs, /* number of subdevices */
const char *name)
{ /* name for the new device */
int i;
size_t size;
struct mtd_concat *concat;
uint32_t max_erasesize, curr_erasesize;
int num_erase_region;
int max_writebufsize = 0;
printk(KERN_NOTICE "Concatenating MTD devices:\n");
for (i = 0; i < num_devs; i++)
printk(KERN_NOTICE "(%d): \"%s\"\n", i, subdev[i]->name);
printk(KERN_NOTICE "into device \"%s\"\n", name);
/* allocate the device structure */
size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
concat = kzalloc(size, GFP_KERNEL);
if (!concat) {
printk
("memory allocation error while creating concatenated device \"%s\"\n",
name);
return NULL;
}
concat->subdev = (struct mtd_info **) (concat + 1);
/*
* Set up the new "super" device's MTD object structure, check for
* incompatibilities between the subdevices.
*/
concat->mtd.type = subdev[0]->type;
concat->mtd.flags = subdev[0]->flags;
concat->mtd.size = subdev[0]->size;
concat->mtd.erasesize = subdev[0]->erasesize;
concat->mtd.writesize = subdev[0]->writesize;
for (i = 0; i < num_devs; i++)
if (max_writebufsize < subdev[i]->writebufsize)
max_writebufsize = subdev[i]->writebufsize;
concat->mtd.writebufsize = max_writebufsize;
concat->mtd.subpage_sft = subdev[0]->subpage_sft;
concat->mtd.oobsize = subdev[0]->oobsize;
concat->mtd.oobavail = subdev[0]->oobavail;
if (subdev[0]->_writev)
concat->mtd._writev = concat_writev;
if (subdev[0]->_read_oob)
concat->mtd._read_oob = concat_read_oob;
if (subdev[0]->_write_oob)
concat->mtd._write_oob = concat_write_oob;
if (subdev[0]->_block_isbad)
concat->mtd._block_isbad = concat_block_isbad;
if (subdev[0]->_block_markbad)
concat->mtd._block_markbad = concat_block_markbad;
concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
concat->subdev[0] = subdev[0];
for (i = 1; i < num_devs; i++) {
if (concat->mtd.type != subdev[i]->type) {
kfree(concat);
printk("Incompatible device type on \"%s\"\n",
subdev[i]->name);
return NULL;
}
if (concat->mtd.flags != subdev[i]->flags) {
/*
* Expect all flags except MTD_WRITEABLE to be
* equal on all subdevices.
*/
if ((concat->mtd.flags ^ subdev[i]->
flags) & ~MTD_WRITEABLE) {
kfree(concat);
printk("Incompatible device flags on \"%s\"\n",
subdev[i]->name);
return NULL;
} else
/* if writeable attribute differs,
make super device writeable */
concat->mtd.flags |=
subdev[i]->flags & MTD_WRITEABLE;
}
concat->mtd.size += subdev[i]->size;
concat->mtd.ecc_stats.badblocks +=
subdev[i]->ecc_stats.badblocks;
if (concat->mtd.writesize != subdev[i]->writesize ||
concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
concat->mtd.oobsize != subdev[i]->oobsize ||
!concat->mtd._read_oob != !subdev[i]->_read_oob ||
!concat->mtd._write_oob != !subdev[i]->_write_oob) {
kfree(concat);
printk("Incompatible OOB or ECC data on \"%s\"\n",
subdev[i]->name);
return NULL;
}
concat->subdev[i] = subdev[i];
}
mtd_set_ooblayout(&concat->mtd, subdev[0]->ooblayout);
concat->num_subdev = num_devs;
concat->mtd.name = name;
concat->mtd._erase = concat_erase;
concat->mtd._read = concat_read;
concat->mtd._write = concat_write;
concat->mtd._sync = concat_sync;
concat->mtd._lock = concat_lock;
concat->mtd._unlock = concat_unlock;
concat->mtd._suspend = concat_suspend;
concat->mtd._resume = concat_resume;
concat->mtd._get_unmapped_area = concat_get_unmapped_area;
/*
* Combine the erase block size info of the subdevices:
*
* first, walk the map of the new device and see how
* many changes in erase size we have
*/
max_erasesize = curr_erasesize = subdev[0]->erasesize;
num_erase_region = 1;
for (i = 0; i < num_devs; i++) {
if (subdev[i]->numeraseregions == 0) {
/* current subdevice has uniform erase size */
if (subdev[i]->erasesize != curr_erasesize) {
/* if it differs from the last subdevice's erase size, count it */
++num_erase_region;
curr_erasesize = subdev[i]->erasesize;
if (curr_erasesize > max_erasesize)
max_erasesize = curr_erasesize;
}
} else {
/* current subdevice has variable erase size */
int j;
for (j = 0; j < subdev[i]->numeraseregions; j++) {
/* walk the list of erase regions, count any changes */
if (subdev[i]->eraseregions[j].erasesize !=
curr_erasesize) {
++num_erase_region;
curr_erasesize =
subdev[i]->eraseregions[j].
erasesize;
if (curr_erasesize > max_erasesize)
max_erasesize = curr_erasesize;
}
}
}
}
if (num_erase_region == 1) {
/*
* All subdevices have the same uniform erase size.
* This is easy:
*/
concat->mtd.erasesize = curr_erasesize;
concat->mtd.numeraseregions = 0;
} else {
uint64_t tmp64;
/*
* erase block size varies across the subdevices: allocate
* space to store the data describing the variable erase regions
*/
struct mtd_erase_region_info *erase_region_p;
uint64_t begin, position;
concat->mtd.erasesize = max_erasesize;
concat->mtd.numeraseregions = num_erase_region;
concat->mtd.eraseregions = erase_region_p =
kmalloc(num_erase_region *
sizeof (struct mtd_erase_region_info), GFP_KERNEL);
if (!erase_region_p) {
kfree(concat);
printk
("memory allocation error while creating erase region list"
" for device \"%s\"\n", name);
return NULL;
}
/*
* walk the map of the new device once more and fill in
* in erase region info:
*/
curr_erasesize = subdev[0]->erasesize;
begin = position = 0;
for (i = 0; i < num_devs; i++) {
if (subdev[i]->numeraseregions == 0) {
/* current subdevice has uniform erase size */
if (subdev[i]->erasesize != curr_erasesize) {
/*
* fill in an mtd_erase_region_info structure for the area
* we have walked so far:
*/
erase_region_p->offset = begin;
erase_region_p->erasesize =
curr_erasesize;
tmp64 = position - begin;
do_div(tmp64, curr_erasesize);
erase_region_p->numblocks = tmp64;
begin = position;
curr_erasesize = subdev[i]->erasesize;
++erase_region_p;
}
position += subdev[i]->size;
} else {
/* current subdevice has variable erase size */
int j;
for (j = 0; j < subdev[i]->numeraseregions; j++) {
/* walk the list of erase regions, count any changes */
if (subdev[i]->eraseregions[j].
erasesize != curr_erasesize) {
erase_region_p->offset = begin;
erase_region_p->erasesize =
curr_erasesize;
tmp64 = position - begin;
do_div(tmp64, curr_erasesize);
erase_region_p->numblocks = tmp64;
begin = position;
curr_erasesize =
subdev[i]->eraseregions[j].
erasesize;
++erase_region_p;
}
position +=
subdev[i]->eraseregions[j].
numblocks * (uint64_t)curr_erasesize;
}
}
}
/* Now write the final entry */
erase_region_p->offset = begin;
erase_region_p->erasesize = curr_erasesize;
tmp64 = position - begin;
do_div(tmp64, curr_erasesize);
erase_region_p->numblocks = tmp64;
}
return &concat->mtd;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 1025 | 79.40% | 2 | 10.53% |
alexander belyakov | alexander belyakov | 54 | 4.18% | 1 | 5.26% |
thomas gleixner | thomas gleixner | 47 | 3.64% | 2 | 10.53% |
adrian hunter | adrian hunter | 46 | 3.56% | 1 | 5.26% |
holger brunck | holger brunck | 37 | 2.87% | 1 | 5.26% |
artem bityutskiy | artem bityutskiy | 23 | 1.78% | 1 | 5.26% |
vitaly wool | vitaly wool | 13 | 1.01% | 1 | 5.26% |
chris paulson-ellis | chris paulson-ellis | 13 | 1.01% | 1 | 5.26% |
anatolij gustschin | anatolij gustschin | 12 | 0.93% | 1 | 5.26% |
david howells | david howells | 7 | 0.54% | 1 | 5.26% |
boris brezillon | boris brezillon | 6 | 0.46% | 2 | 10.53% |
joern engel | joern engel | 4 | 0.31% | 1 | 5.26% |
david woodhouse | david woodhouse | 1 | 0.08% | 1 | 5.26% |
brian norris | brian norris | 1 | 0.08% | 1 | 5.26% |
burman yan | burman yan | 1 | 0.08% | 1 | 5.26% |
kay sievers | kay sievers | 1 | 0.08% | 1 | 5.26% |
| Total | 1291 | 100.00% | 19 | 100.00% |
/*
* This function destroys an MTD object obtained from concat_mtd_devs()
*/
void mtd_concat_destroy(struct mtd_info *mtd)
{
struct mtd_concat *concat = CONCAT(mtd);
if (concat->mtd.numeraseregions)
kfree(concat->mtd.eraseregions);
kfree(concat);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 42 | 100.00% | 1 | 100.00% |
| Total | 42 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(mtd_concat_create);
EXPORT_SYMBOL(mtd_concat_destroy);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Robert Kaiser <rkaiser@sysgo.de>");
MODULE_DESCRIPTION("Generic support for concatenating of MTD devices");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
russell king | russell king | 2523 | 59.73% | 2 | 3.77% |
alexander belyakov | alexander belyakov | 634 | 15.01% | 1 | 1.89% |
david woodhouse | david woodhouse | 316 | 7.48% | 5 | 9.43% |
thomas gleixner | thomas gleixner | 313 | 7.41% | 7 | 13.21% |
david howells | david howells | 113 | 2.68% | 1 | 1.89% |
vitaly wool | vitaly wool | 92 | 2.18% | 2 | 3.77% |
adrian hunter | adrian hunter | 55 | 1.30% | 2 | 3.77% |
artem bityutskiy | artem bityutskiy | 40 | 0.95% | 16 | 30.19% |
holger brunck | holger brunck | 37 | 0.88% | 1 | 1.89% |
andrew morton | andrew morton | 14 | 0.33% | 1 | 1.89% |
brian norris | brian norris | 13 | 0.31% | 2 | 3.77% |
chris paulson-ellis | chris paulson-ellis | 13 | 0.31% | 1 | 1.89% |
anatolij gustschin | anatolij gustschin | 12 | 0.28% | 1 | 1.89% |
roel kluin | roel kluin | 10 | 0.24% | 1 | 1.89% |
niklas cassel | niklas cassel | 8 | 0.19% | 1 | 1.89% |
joern engel | joern engel | 7 | 0.17% | 1 | 1.89% |
boris brezillon | boris brezillon | 6 | 0.14% | 2 | 3.77% |
eric sesterhenn | eric sesterhenn | 6 | 0.14% | 1 | 1.89% |
felix radensky | felix radensky | 5 | 0.12% | 1 | 1.89% |
julia lawall | julia lawall | 3 | 0.07% | 1 | 1.89% |
tim schmielau | tim schmielau | 2 | 0.05% | 1 | 1.89% |
kay sievers | kay sievers | 1 | 0.02% | 1 | 1.89% |
burman yan | burman yan | 1 | 0.02% | 1 | 1.89% |
| Total | 4224 | 100.00% | 53 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.