machvec.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * arch/sh/kernel/machvec.c
  3. *
  4. * The SuperH machine vector setup handlers, yanked from setup.c
  5. *
  6. * Copyright (C) 1999 Niibe Yutaka
  7. * Copyright (C) 2002 - 2007 Paul Mundt
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/string.h>
  15. #include <asm/machvec.h>
  16. #include <asm/sections.h>
  17. #include <asm/setup.h>
  18. #include <asm/io.h>
  19. #include <asm/irq.h>
  20. #define MV_NAME_SIZE 32
  21. #define for_each_mv(mv) \
  22. for ((mv) = (struct sh_machine_vector *)&__machvec_start; \
  23. (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \
  24. (mv)++)
  25. static struct sh_machine_vector * __init get_mv_byname(const char *name)
  26. {
  27. struct sh_machine_vector *mv;
  28. for_each_mv(mv)
  29. if (strcasecmp(name, mv->mv_name) == 0)
  30. return mv;
  31. return NULL;
  32. }
  33. static unsigned int __initdata machvec_selected;
  34. static int __init early_parse_mv(char *from)
  35. {
  36. char mv_name[MV_NAME_SIZE] = "";
  37. char *mv_end;
  38. char *mv_comma;
  39. int mv_len;
  40. struct sh_machine_vector *mvp;
  41. mv_end = strchr(from, ' ');
  42. if (mv_end == NULL)
  43. mv_end = from + strlen(from);
  44. mv_comma = strchr(from, ',');
  45. mv_len = mv_end - from;
  46. if (mv_len > (MV_NAME_SIZE-1))
  47. mv_len = MV_NAME_SIZE-1;
  48. memcpy(mv_name, from, mv_len);
  49. mv_name[mv_len] = '\0';
  50. from = mv_end;
  51. machvec_selected = 1;
  52. /* Boot with the generic vector */
  53. if (strcmp(mv_name, "generic") == 0)
  54. return 0;
  55. mvp = get_mv_byname(mv_name);
  56. if (unlikely(!mvp)) {
  57. printk("Available vectors:\n\n\t'%s', ", sh_mv.mv_name);
  58. for_each_mv(mvp)
  59. printk("'%s', ", mvp->mv_name);
  60. printk("\n\n");
  61. panic("Failed to select machvec '%s' -- halting.\n",
  62. mv_name);
  63. } else
  64. sh_mv = *mvp;
  65. return 0;
  66. }
  67. early_param("sh_mv", early_parse_mv);
  68. void __init sh_mv_setup(void)
  69. {
  70. /*
  71. * Only overload the machvec if one hasn't been selected on
  72. * the command line with sh_mv=
  73. */
  74. if (!machvec_selected) {
  75. unsigned long machvec_size;
  76. machvec_size = ((unsigned long)&__machvec_end -
  77. (unsigned long)&__machvec_start);
  78. /*
  79. * Sanity check for machvec section alignment. Ensure
  80. * __initmv hasn't been misused.
  81. */
  82. if (machvec_size % sizeof(struct sh_machine_vector))
  83. panic("machvec misaligned, invalid __initmv use?");
  84. /*
  85. * If the machvec hasn't been preselected, use the first
  86. * vector (usually the only one) from .machvec.init.
  87. */
  88. if (machvec_size >= sizeof(struct sh_machine_vector))
  89. sh_mv = *(struct sh_machine_vector *)&__machvec_start;
  90. }
  91. printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type());
  92. /*
  93. * Manually walk the vec, fill in anything that the board hasn't yet
  94. * by hand, wrapping to the generic implementation.
  95. */
  96. #define mv_set(elem) do { \
  97. if (!sh_mv.mv_##elem) \
  98. sh_mv.mv_##elem = generic_##elem; \
  99. } while (0)
  100. mv_set(inb); mv_set(inw); mv_set(inl);
  101. mv_set(outb); mv_set(outw); mv_set(outl);
  102. mv_set(inb_p); mv_set(inw_p); mv_set(inl_p);
  103. mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
  104. mv_set(insb); mv_set(insw); mv_set(insl);
  105. mv_set(outsb); mv_set(outsw); mv_set(outsl);
  106. mv_set(ioport_map);
  107. mv_set(ioport_unmap);
  108. mv_set(irq_demux);
  109. mv_set(mode_pins);
  110. if (!sh_mv.mv_nr_irqs)
  111. sh_mv.mv_nr_irqs = NR_IRQS;
  112. }