cregit-Linux how code gets into the kernel

Release 4.7 drivers/mtd/chips/map_ram.c

/*
 * Common code to handle map devices which are simple RAM
 * (C) 2000 Red Hat. GPL'd.
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <asm/byteorder.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>


static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
static int mapram_erase (struct mtd_info *, struct erase_info *);
static void mapram_nop (struct mtd_info *);
static struct mtd_info *map_ram_probe(struct map_info *map);
static unsigned long mapram_unmapped_area(struct mtd_info *, unsigned long,
					  unsigned long, unsigned long);



static struct mtd_chip_driver mapram_chipdrv = {
	.probe	= map_ram_probe,
	.name	= "map_ram",
	.module	= THIS_MODULE
};


static struct mtd_info *map_ram_probe(struct map_info *map) { struct mtd_info *mtd; /* Check the first byte is RAM */ #if 0 map_write8(map, 0x55, 0); if (map_read8(map, 0) != 0x55) return NULL; map_write8(map, 0xAA, 0); if (map_read8(map, 0) != 0xAA) return NULL; /* Check the last byte is RAM */ map_write8(map, 0x55, map->size-1); if (map_read8(map, map->size-1) != 0x55) return NULL; map_write8(map, 0xAA, map->size-1); if (map_read8(map, map->size-1) != 0xAA) return NULL; #endif /* OK. It seems to be RAM. */ mtd = kzalloc(sizeof(*mtd), GFP_KERNEL); if (!mtd) return NULL; map->fldrv = &mapram_chipdrv; mtd->priv = map; mtd->name = map->name; mtd->type = MTD_RAM; mtd->size = map->size; mtd->_erase = mapram_erase; mtd->_get_unmapped_area = mapram_unmapped_area; mtd->_read = mapram_read; mtd->_write = mapram_write; mtd->_panic_write = mapram_write; mtd->_sync = mapram_nop; mtd->flags = MTD_CAP_RAM; mtd->writesize = 1; mtd->erasesize = PAGE_SIZE; while(mtd->size & (mtd->erasesize - 1)) mtd->erasesize >>= 1; __module_get(THIS_MODULE); return mtd; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10865.06%325.00%
linus torvaldslinus torvalds2816.87%216.67%
artem bityutskiyartem bityutskiy116.63%216.67%
david woodhousedavid woodhouse74.22%216.67%
alessio igor boganialessio igor bogani63.61%18.33%
david howellsdavid howells53.01%18.33%
burman yanburman yan10.60%18.33%
Total166100.00%12100.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 mapram_unmapped_area(struct mtd_info *mtd, unsigned long len, unsigned long offset, unsigned long flags) { struct map_info *map = mtd->priv; return (unsigned long) map->virt + offset; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells44100.00%1100.00%
Total44100.00%1100.00%


static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct map_info *map = mtd->priv; map_copy_from(map, buf, from, len); *retlen = len; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5298.11%150.00%
david woodhousedavid woodhouse11.89%150.00%
Total53100.00%2100.00%


static int mapram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { struct map_info *map = mtd->priv; map_copy_to(map, to, buf, len); *retlen = len; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5398.15%150.00%
david woodhousedavid woodhouse11.85%150.00%
Total54100.00%2100.00%


static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr) { /* Yeah, it's inefficient. Who cares? It's faster than a _real_ flash erase. */ struct map_info *map = mtd->priv; map_word allff; unsigned long i; allff = map_word_ff(map); for (i=0; i<instr->len; i += map_bankwidth(map)) map_write(map, allff, instr->addr + i); instr->state = MTD_ERASE_DONE; mtd_erase_callback(instr); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git6272.09%133.33%
david woodhousedavid woodhouse2427.91%266.67%
Total86100.00%3100.00%


static void mapram_nop(struct mtd_info *mtd) { /* Nothing to see here */ }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git12100.00%1100.00%
Total12100.00%1100.00%


static int __init map_ram_init(void) { register_mtd_chip_driver(&mapram_chipdrv); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1583.33%133.33%
linus torvaldslinus torvalds211.11%133.33%
david woodhousedavid woodhouse15.56%133.33%
Total18100.00%3100.00%


static void __exit map_ram_exit(void) { unregister_mtd_chip_driver(&mapram_chipdrv); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1280.00%150.00%
linus torvaldslinus torvalds320.00%150.00%
Total15100.00%2100.00%

module_init(map_ram_init); module_exit(map_ram_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); MODULE_DESCRIPTION("MTD chip driver for RAM chips");

Overall Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git41166.40%316.67%
linus torvaldslinus torvalds7411.95%316.67%
david howellsdavid howells6911.15%15.56%
david woodhousedavid woodhouse406.46%527.78%
artem bityutskiyartem bityutskiy111.78%211.11%
alessio igor boganialessio igor bogani60.97%15.56%
art haasart haas60.97%15.56%
adrian bunkadrian bunk10.16%15.56%
burman yanburman yan10.16%15.56%
Total619100.00%18100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}