uclinux.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************/
  2. /*
  3. * uclinux.c -- generic memory mapped MTD driver for uclinux
  4. *
  5. * (C) Copyright 2002, Greg Ungerer ([email protected])
  6. *
  7. * License: GPL
  8. */
  9. /****************************************************************************/
  10. #include <linux/moduleparam.h>
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/fs.h>
  15. #include <linux/mm.h>
  16. #include <linux/major.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/io.h>
  21. #include <asm/sections.h>
  22. /****************************************************************************/
  23. #ifdef CONFIG_MTD_ROM
  24. #define MAP_NAME "rom"
  25. #else
  26. #define MAP_NAME "ram"
  27. #endif
  28. static struct map_info uclinux_ram_map = {
  29. .name = MAP_NAME,
  30. .size = 0,
  31. };
  32. static unsigned long physaddr = -1;
  33. module_param(physaddr, ulong, S_IRUGO);
  34. static struct mtd_info *uclinux_ram_mtdinfo;
  35. /****************************************************************************/
  36. static const struct mtd_partition uclinux_romfs[] = {
  37. { .name = "ROMfs" }
  38. };
  39. #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
  40. /****************************************************************************/
  41. static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  42. size_t *retlen, void **virt, resource_size_t *phys)
  43. {
  44. struct map_info *map = mtd->priv;
  45. *virt = map->virt + from;
  46. if (phys)
  47. *phys = map->phys + from;
  48. *retlen = len;
  49. return(0);
  50. }
  51. /****************************************************************************/
  52. static int __init uclinux_mtd_init(void)
  53. {
  54. struct mtd_info *mtd;
  55. struct map_info *mapp;
  56. mapp = &uclinux_ram_map;
  57. if (physaddr == -1)
  58. mapp->phys = (resource_size_t)__bss_stop;
  59. else
  60. mapp->phys = physaddr;
  61. if (!mapp->size)
  62. mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
  63. mapp->bankwidth = 4;
  64. printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
  65. (int) mapp->phys, (int) mapp->size);
  66. /*
  67. * The filesystem is guaranteed to be in direct mapped memory. It is
  68. * directly following the kernels own bss region. Following the same
  69. * mechanism used by architectures setting up traditional initrds we
  70. * use phys_to_virt to get the virtual address of its start.
  71. */
  72. mapp->virt = phys_to_virt(mapp->phys);
  73. if (mapp->virt == 0) {
  74. printk("uclinux[mtd]: no virtual mapping?\n");
  75. return(-EIO);
  76. }
  77. simple_map_init(mapp);
  78. mtd = do_map_probe("map_" MAP_NAME, mapp);
  79. if (!mtd) {
  80. printk("uclinux[mtd]: failed to find a mapping?\n");
  81. return(-ENXIO);
  82. }
  83. mtd->owner = THIS_MODULE;
  84. mtd->_point = uclinux_point;
  85. mtd->priv = mapp;
  86. uclinux_ram_mtdinfo = mtd;
  87. mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
  88. return(0);
  89. }
  90. device_initcall(uclinux_mtd_init);
  91. /****************************************************************************/