Release 4.7 drivers/mtd/devices/mtdram.c
  
  
/*
 * mtdram - a test mtd device
 * Author: Alexander Larsson <alex@cendio.se>
 *
 * Copyright (c) 1999 Alexander Larsson <alex@cendio.se>
 * Copyright (c) 2005 Joern Engel <joern@wh.fh-wedel.de>
 *
 * This code is GPL
 *
 */
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/mtdram.h>
static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE;
static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE;
static unsigned long writebuf_size = 64;
#define MTDRAM_TOTAL_SIZE (total_size * 1024)
#define MTDRAM_ERASE_SIZE (erase_size * 1024)
#ifdef MODULE
module_param(total_size, ulong, 0);
MODULE_PARM_DESC(total_size, "Total device size in KiB");
module_param(erase_size, ulong, 0);
MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
module_param(writebuf_size, ulong, 0);
MODULE_PARM_DESC(writebuf_size, "Device write buf size in Bytes (Default: 64)");
#endif
// We could store these in the mtd structure, but we only support 1 device..
static struct mtd_info *mtd_info;
static int check_offs_len(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
	int ret = 0;
	/* Start address must align on block boundary */
	if (mtd_mod_by_eb(ofs, mtd)) {
		pr_debug("%s: unaligned address\n", __func__);
		ret = -EINVAL;
	}
	/* Length must align on block boundary */
	if (mtd_mod_by_eb(len, mtd)) {
		pr_debug("%s: length not block aligned\n", __func__);
		ret = -EINVAL;
	}
	return ret;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| dongsheng yang | dongsheng yang | 73 | 100.00% | 1 | 100.00% | 
 | Total | 73 | 100.00% | 1 | 100.00% | 
static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
{
	if (check_offs_len(mtd, instr->addr, instr->len))
		return -EINVAL;
	memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
	instr->state = MTD_ERASE_DONE;
	mtd_erase_callback(instr);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 48 | 68.57% | 1 | 33.33% | 
| dongsheng yang | dongsheng yang | 19 | 27.14% | 1 | 33.33% | 
| david woodhouse | david woodhouse | 3 | 4.29% | 1 | 33.33% | 
 | Total | 70 | 100.00% | 3 | 100.00% | 
static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, void **virt, resource_size_t *phys)
{
	*virt = mtd->priv + from;
	*retlen = len;
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 40 | 85.11% | 1 | 50.00% | 
| jared hulbert | jared hulbert | 7 | 14.89% | 1 | 50.00% | 
 | Total | 47 | 100.00% | 2 | 100.00% | 
static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 9 | 45.00% | 1 | 33.33% | 
| artem bityutskiy | artem bityutskiy | 6 | 30.00% | 1 | 33.33% | 
| david woodhouse | david woodhouse | 5 | 25.00% | 1 | 33.33% | 
 | Total | 20 | 100.00% | 3 | 100.00% | 
/*
 * Allow NOMMU mmap() to directly map the device (if not NULL)
 * - return the address to which the offset maps
 * - return -ENOSYS to indicate refusal to do the mapping
 */
static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
					   unsigned long len,
					   unsigned long offset,
					   unsigned long flags)
{
	return (unsigned long) mtd->priv + offset;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david howells | david howells | 35 | 100.00% | 1 | 100.00% | 
 | Total | 35 | 100.00% | 1 | 100.00% | 
static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, u_char *buf)
{
	memcpy(buf, mtd->priv + from, len);
	*retlen = len;
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 46 | 100.00% | 1 | 100.00% | 
 | Total | 46 | 100.00% | 1 | 100.00% | 
static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
		size_t *retlen, const u_char *buf)
{
	memcpy((char *)mtd->priv + to, buf, len);
	*retlen = len;
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 51 | 100.00% | 1 | 100.00% | 
 | Total | 51 | 100.00% | 1 | 100.00% | 
static void __exit cleanup_mtdram(void)
{
	if (mtd_info) {
		mtd_device_unregister(mtd_info);
		vfree(mtd_info->priv);
		kfree(mtd_info);
	}
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 28 | 87.50% | 1 | 33.33% | 
| linus torvalds | linus torvalds | 3 | 9.38% | 1 | 33.33% | 
| jamie iles | jamie iles | 1 | 3.12% | 1 | 33.33% | 
 | Total | 32 | 100.00% | 3 | 100.00% | 
int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
		unsigned long size, const char *name)
{
	memset(mtd, 0, sizeof(*mtd));
	/* Setup the MTD structure */
	mtd->name = name;
	mtd->type = MTD_RAM;
	mtd->flags = MTD_CAP_RAM;
	mtd->size = size;
	mtd->writesize = 1;
	mtd->writebufsize = writebuf_size;
	mtd->erasesize = MTDRAM_ERASE_SIZE;
	mtd->priv = mapped_address;
	mtd->owner = THIS_MODULE;
	mtd->_erase = ram_erase;
	mtd->_point = ram_point;
	mtd->_unpoint = ram_unpoint;
	mtd->_get_unmapped_area = ram_get_unmapped_area;
	mtd->_read = ram_read;
	mtd->_write = ram_write;
	if (mtd_device_register(mtd, NULL, 0))
		return -EIO;
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david woodhouse | david woodhouse | 78 | 53.79% | 2 | 18.18% | 
| pre-git | pre-git | 37 | 25.52% | 1 | 9.09% | 
| artem bityutskiy | artem bityutskiy | 17 | 11.72% | 3 | 27.27% | 
| david howells | david howells | 5 | 3.45% | 1 | 9.09% | 
| jamie iles | jamie iles | 5 | 3.45% | 1 | 9.09% | 
| brian norris | brian norris | 1 | 0.69% | 1 | 9.09% | 
| linus torvalds | linus torvalds | 1 | 0.69% | 1 | 9.09% | 
| alexander stein | alexander stein | 1 | 0.69% | 1 | 9.09% | 
 | Total | 145 | 100.00% | 11 | 100.00% | 
static int __init init_mtdram(void)
{
	void *addr;
	int err;
	if (!total_size)
		return -EINVAL;
	/* Allocate some memory */
	mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
	if (!mtd_info)
		return -ENOMEM;
	addr = vmalloc(MTDRAM_TOTAL_SIZE);
	if (!addr) {
		kfree(mtd_info);
		mtd_info = NULL;
		return -ENOMEM;
	}
	err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device");
	if (err) {
		vfree(addr);
		kfree(mtd_info);
		mtd_info = NULL;
		return err;
	}
	memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
	return err;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david woodhouse | david woodhouse | 89 | 71.20% | 2 | 40.00% | 
| pre-git | pre-git | 30 | 24.00% | 1 | 20.00% | 
| linus torvalds | linus torvalds | 4 | 3.20% | 1 | 20.00% | 
| joern engel | joern engel | 2 | 1.60% | 1 | 20.00% | 
 | Total | 125 | 100.00% | 5 | 100.00% | 
module_init(init_mtdram);
module_exit(cleanup_mtdram);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>");
MODULE_DESCRIPTION("Simulated MTD driver for testing");
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| pre-git | pre-git | 317 | 40.59% | 1 | 4.55% | 
| david woodhouse | david woodhouse | 195 | 24.97% | 4 | 18.18% | 
| dongsheng yang | dongsheng yang | 92 | 11.78% | 1 | 4.55% | 
| linus torvalds | linus torvalds | 50 | 6.40% | 3 | 13.64% | 
| david howells | david howells | 41 | 5.25% | 1 | 4.55% | 
| alexander stein | alexander stein | 24 | 3.07% | 1 | 4.55% | 
| artem bityutskiy | artem bityutskiy | 23 | 2.94% | 4 | 18.18% | 
| joern engel | joern engel | 13 | 1.66% | 1 | 4.55% | 
| andrew morton | andrew morton | 8 | 1.02% | 1 | 4.55% | 
| jared hulbert | jared hulbert | 7 | 0.90% | 1 | 4.55% | 
| jamie iles | jamie iles | 6 | 0.77% | 1 | 4.55% | 
| adrian bunk | adrian bunk | 4 | 0.51% | 2 | 9.09% | 
| brian norris | brian norris | 1 | 0.13% | 1 | 4.55% | 
 | Total | 781 | 100.00% | 22 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.