uclinux.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include <asm/sections.h>
  20. /****************************************************************************/
  21. #ifdef CONFIG_MTD_ROM
  22. #define MAP_NAME "rom"
  23. #else
  24. #define MAP_NAME "ram"
  25. #endif
  26. struct map_info uclinux_ram_map = {
  27. .name = MAP_NAME,
  28. .size = 0,
  29. };
  30. static unsigned long physaddr = -1;
  31. module_param(physaddr, ulong, S_IRUGO);
  32. static struct mtd_info *uclinux_ram_mtdinfo;
  33. /****************************************************************************/
  34. static struct mtd_partition uclinux_romfs[] = {
  35. { .name = "ROMfs" }
  36. };
  37. #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
  38. /****************************************************************************/
  39. static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  40. size_t *retlen, void **virt, resource_size_t *phys)
  41. {
  42. struct map_info *map = mtd->priv;
  43. *virt = map->virt + from;
  44. if (phys)
  45. *phys = map->phys + from;
  46. *retlen = len;
  47. return(0);
  48. }
  49. /****************************************************************************/
  50. static int __init uclinux_mtd_init(void)
  51. {
  52. struct mtd_info *mtd;
  53. struct map_info *mapp;
  54. mapp = &uclinux_ram_map;
  55. if (physaddr == -1)
  56. mapp->phys = (resource_size_t)__bss_stop;
  57. else
  58. mapp->phys = physaddr;
  59. if (!mapp->size)
  60. mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
  61. mapp->bankwidth = 4;
  62. printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
  63. (int) mapp->phys, (int) mapp->size);
  64. /*
  65. * The filesystem is guaranteed to be in direct mapped memory. It is
  66. * directly following the kernels own bss region. Following the same
  67. * mechanism used by architectures setting up traditional initrds we
  68. * use phys_to_virt to get the virtual address of its start.
  69. */
  70. mapp->virt = phys_to_virt(mapp->phys);
  71. if (mapp->virt == 0) {
  72. printk("uclinux[mtd]: no virtual mapping?\n");
  73. return(-EIO);
  74. }
  75. simple_map_init(mapp);
  76. mtd = do_map_probe("map_" MAP_NAME, mapp);
  77. if (!mtd) {
  78. printk("uclinux[mtd]: failed to find a mapping?\n");
  79. return(-ENXIO);
  80. }
  81. mtd->owner = THIS_MODULE;
  82. mtd->_point = uclinux_point;
  83. mtd->priv = mapp;
  84. uclinux_ram_mtdinfo = mtd;
  85. mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
  86. return(0);
  87. }
  88. /****************************************************************************/
  89. static void __exit uclinux_mtd_cleanup(void)
  90. {
  91. if (uclinux_ram_mtdinfo) {
  92. mtd_device_unregister(uclinux_ram_mtdinfo);
  93. map_destroy(uclinux_ram_mtdinfo);
  94. uclinux_ram_mtdinfo = NULL;
  95. }
  96. if (uclinux_ram_map.virt)
  97. uclinux_ram_map.virt = 0;
  98. }
  99. /****************************************************************************/
  100. module_init(uclinux_mtd_init);
  101. module_exit(uclinux_mtd_cleanup);
  102. MODULE_LICENSE("GPL");
  103. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  104. MODULE_DESCRIPTION("Generic MTD for uClinux");
  105. /****************************************************************************/