machvec.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/addrspace.h>
  18. #include <asm/setup.h>
  19. #include <asm/io.h>
  20. #include <asm/irq.h>
  21. #define MV_NAME_SIZE 32
  22. #define for_each_mv(mv) \
  23. for ((mv) = (struct sh_machine_vector *)&__machvec_start; \
  24. (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \
  25. (mv)++)
  26. static struct sh_machine_vector * __init get_mv_byname(const char *name)
  27. {
  28. struct sh_machine_vector *mv;
  29. for_each_mv(mv)
  30. if (strcasecmp(name, mv->mv_name) == 0)
  31. return mv;
  32. return NULL;
  33. }
  34. static unsigned int __initdata machvec_selected;
  35. static int __init early_parse_mv(char *from)
  36. {
  37. char mv_name[MV_NAME_SIZE] = "";
  38. char *mv_end;
  39. char *mv_comma;
  40. int mv_len;
  41. struct sh_machine_vector *mvp;
  42. mv_end = strchr(from, ' ');
  43. if (mv_end == NULL)
  44. mv_end = from + strlen(from);
  45. mv_comma = strchr(from, ',');
  46. mv_len = mv_end - from;
  47. if (mv_len > (MV_NAME_SIZE-1))
  48. mv_len = MV_NAME_SIZE-1;
  49. memcpy(mv_name, from, mv_len);
  50. mv_name[mv_len] = '\0';
  51. from = mv_end;
  52. machvec_selected = 1;
  53. /* Boot with the generic vector */
  54. if (strcmp(mv_name, "generic") == 0)
  55. return 0;
  56. mvp = get_mv_byname(mv_name);
  57. if (unlikely(!mvp)) {
  58. printk("Available vectors:\n\n\t'%s', ", sh_mv.mv_name);
  59. for_each_mv(mvp)
  60. printk("'%s', ", mvp->mv_name);
  61. printk("\n\n");
  62. panic("Failed to select machvec '%s' -- halting.\n",
  63. mv_name);
  64. } else
  65. sh_mv = *mvp;
  66. return 0;
  67. }
  68. early_param("sh_mv", early_parse_mv);
  69. void __init sh_mv_setup(void)
  70. {
  71. /*
  72. * Only overload the machvec if one hasn't been selected on
  73. * the command line with sh_mv=
  74. */
  75. if (!machvec_selected) {
  76. unsigned long machvec_size;
  77. machvec_size = ((unsigned long)&__machvec_end -
  78. (unsigned long)&__machvec_start);
  79. /*
  80. * Sanity check for machvec section alignment. Ensure
  81. * __initmv hasn't been misused.
  82. */
  83. if (machvec_size % sizeof(struct sh_machine_vector))
  84. panic("machvec misaligned, invalid __initmv use?");
  85. /*
  86. * If the machvec hasn't been preselected, use the first
  87. * vector (usually the only one) from .machvec.init.
  88. */
  89. if (machvec_size >= sizeof(struct sh_machine_vector))
  90. sh_mv = *(struct sh_machine_vector *)&__machvec_start;
  91. }
  92. printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type());
  93. /*
  94. * Manually walk the vec, fill in anything that the board hasn't yet
  95. * by hand, wrapping to the generic implementation.
  96. */
  97. #define mv_set(elem) do { \
  98. if (!sh_mv.mv_##elem) \
  99. sh_mv.mv_##elem = generic_##elem; \
  100. } while (0)
  101. mv_set(irq_demux);
  102. mv_set(mode_pins);
  103. mv_set(mem_init);
  104. }