uclinux.c 3.5 KB

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