machvec.c 2.8 KB

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