pmcmsp-ramroot.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Mapping of the rootfs in a physical region of memory
  3. *
  4. * Copyright (C) 2005-2007 PMC-Sierra Inc.
  5. * Author: Andrew Hughes, Andrew_Hughes@pmc-sierra.com
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/module.h>
  28. #include <linux/types.h>
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include <linux/slab.h>
  32. #include <linux/fs.h>
  33. #include <linux/root_dev.h>
  34. #include <linux/mtd/mtd.h>
  35. #include <linux/mtd/map.h>
  36. #include <asm/io.h>
  37. #include <msp_prom.h>
  38. static struct mtd_info *rr_mtd;
  39. struct map_info rr_map = {
  40. .name = "ramroot",
  41. .bankwidth = 4,
  42. };
  43. static int __init init_rrmap(void)
  44. {
  45. void *ramroot_start;
  46. unsigned long ramroot_size;
  47. /* Check for supported rootfs types */
  48. if (get_ramroot(&ramroot_start, &ramroot_size)) {
  49. rr_map.phys = CPHYSADDR(ramroot_start);
  50. rr_map.size = ramroot_size;
  51. printk(KERN_NOTICE
  52. "PMC embedded root device: 0x%08lx @ 0x%08lx\n",
  53. rr_map.size, (unsigned long)rr_map.phys);
  54. } else {
  55. printk(KERN_ERR
  56. "init_rrmap: no supported embedded rootfs detected!\n");
  57. return -ENXIO;
  58. }
  59. /* Map rootfs to I/O space for block device driver */
  60. rr_map.virt = ioremap(rr_map.phys, rr_map.size);
  61. if (!rr_map.virt) {
  62. printk(KERN_ERR "Failed to ioremap\n");
  63. return -EIO;
  64. }
  65. simple_map_init(&rr_map);
  66. rr_mtd = do_map_probe("map_ram", &rr_map);
  67. if (rr_mtd) {
  68. rr_mtd->owner = THIS_MODULE;
  69. add_mtd_device(rr_mtd);
  70. return 0;
  71. }
  72. iounmap(rr_map.virt);
  73. return -ENXIO;
  74. }
  75. static void __exit cleanup_rrmap(void)
  76. {
  77. del_mtd_device(rr_mtd);
  78. map_destroy(rr_mtd);
  79. iounmap(rr_map.virt);
  80. rr_map.virt = NULL;
  81. }
  82. MODULE_AUTHOR("PMC-Sierra, Inc");
  83. MODULE_DESCRIPTION("MTD map driver for embedded PMC-Sierra MSP filesystem");
  84. MODULE_LICENSE("GPL");
  85. module_init(init_rrmap);
  86. module_exit(cleanup_rrmap);