uclinux.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /****************************************************************************/
  2. /*
  3. * uclinux.c -- generic memory mapped MTD driver for uclinux
  4. *
  5. * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
  6. */
  7. /****************************************************************************/
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/fs.h>
  13. #include <linux/mm.h>
  14. #include <linux/major.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/map.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <asm/io.h>
  19. /****************************************************************************/
  20. extern char _ebss;
  21. struct map_info uclinux_ram_map = {
  22. .name = "RAM",
  23. .phys = (unsigned long)&_ebss,
  24. .size = 0,
  25. };
  26. static struct mtd_info *uclinux_ram_mtdinfo;
  27. /****************************************************************************/
  28. static struct mtd_partition uclinux_romfs[] = {
  29. { .name = "ROMfs" }
  30. };
  31. #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
  32. /****************************************************************************/
  33. static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  34. size_t *retlen, void **virt, resource_size_t *phys)
  35. {
  36. struct map_info *map = mtd->priv;
  37. *virt = map->virt + from;
  38. if (phys)
  39. *phys = map->phys + from;
  40. *retlen = len;
  41. return(0);
  42. }
  43. /****************************************************************************/
  44. static int __init uclinux_mtd_init(void)
  45. {
  46. struct mtd_info *mtd;
  47. struct map_info *mapp;
  48. mapp = &uclinux_ram_map;
  49. if (!mapp->size)
  50. mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
  51. mapp->bankwidth = 4;
  52. printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
  53. (int) mapp->phys, (int) mapp->size);
  54. mapp->virt = ioremap_nocache(mapp->phys, mapp->size);
  55. if (mapp->virt == 0) {
  56. printk("uclinux[mtd]: ioremap_nocache() failed\n");
  57. return(-EIO);
  58. }
  59. simple_map_init(mapp);
  60. mtd = do_map_probe("map_ram", mapp);
  61. if (!mtd) {
  62. printk("uclinux[mtd]: failed to find a mapping?\n");
  63. iounmap(mapp->virt);
  64. return(-ENXIO);
  65. }
  66. mtd->owner = THIS_MODULE;
  67. mtd->_point = uclinux_point;
  68. mtd->priv = mapp;
  69. uclinux_ram_mtdinfo = mtd;
  70. mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
  71. return(0);
  72. }
  73. /****************************************************************************/
  74. static void __exit uclinux_mtd_cleanup(void)
  75. {
  76. if (uclinux_ram_mtdinfo) {
  77. mtd_device_unregister(uclinux_ram_mtdinfo);
  78. map_destroy(uclinux_ram_mtdinfo);
  79. uclinux_ram_mtdinfo = NULL;
  80. }
  81. if (uclinux_ram_map.virt) {
  82. iounmap((void *) uclinux_ram_map.virt);
  83. uclinux_ram_map.virt = 0;
  84. }
  85. }
  86. /****************************************************************************/
  87. module_init(uclinux_mtd_init);
  88. module_exit(uclinux_mtd_cleanup);
  89. MODULE_LICENSE("GPL");
  90. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  91. MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
  92. /****************************************************************************/