machvec.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/io.h>
  18. #include <asm/irq.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 int __init early_parse_mv(char *from)
  33. {
  34. char mv_name[MV_NAME_SIZE] = "";
  35. char *mv_end;
  36. char *mv_comma;
  37. int mv_len;
  38. struct sh_machine_vector *mvp;
  39. mv_end = strchr(from, ' ');
  40. if (mv_end == NULL)
  41. mv_end = from + strlen(from);
  42. mv_comma = strchr(from, ',');
  43. mv_len = mv_end - from;
  44. if (mv_len > (MV_NAME_SIZE-1))
  45. mv_len = MV_NAME_SIZE-1;
  46. memcpy(mv_name, from, mv_len);
  47. mv_name[mv_len] = '\0';
  48. from = mv_end;
  49. mvp = get_mv_byname(mv_name);
  50. if (unlikely(!mvp)) {
  51. printk("Available vectors:\n\n\t");
  52. for_each_mv(mvp)
  53. printk("'%s', ", mvp->mv_name);
  54. printk("\n\n");
  55. panic("Failed to select machvec '%s' -- halting.\n",
  56. mv_name);
  57. } else
  58. sh_mv = *mvp;
  59. return 0;
  60. }
  61. early_param("sh_mv", early_parse_mv);
  62. void __init sh_mv_setup(void)
  63. {
  64. /*
  65. * Only overload the machvec if one hasn't been selected on
  66. * the command line with sh_mv=
  67. */
  68. if (strcmp(sh_mv.mv_name, "Unknown") != 0) {
  69. unsigned long machvec_size;
  70. machvec_size = ((unsigned long)&__machvec_end -
  71. (unsigned long)&__machvec_start);
  72. /*
  73. * If the machvec hasn't been preselected, use the first
  74. * vector (usually the only one) from .machvec.init.
  75. */
  76. if (machvec_size >= sizeof(struct sh_machine_vector))
  77. sh_mv = *(struct sh_machine_vector *)&__machvec_start;
  78. }
  79. printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type());
  80. /*
  81. * Manually walk the vec, fill in anything that the board hasn't yet
  82. * by hand, wrapping to the generic implementation.
  83. */
  84. #define mv_set(elem) do { \
  85. if (!sh_mv.mv_##elem) \
  86. sh_mv.mv_##elem = generic_##elem; \
  87. } while (0)
  88. mv_set(inb); mv_set(inw); mv_set(inl);
  89. mv_set(outb); mv_set(outw); mv_set(outl);
  90. mv_set(inb_p); mv_set(inw_p); mv_set(inl_p);
  91. mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
  92. mv_set(insb); mv_set(insw); mv_set(insl);
  93. mv_set(outsb); mv_set(outsw); mv_set(outsl);
  94. mv_set(readb); mv_set(readw); mv_set(readl);
  95. mv_set(writeb); mv_set(writew); mv_set(writel);
  96. mv_set(ioport_map);
  97. mv_set(ioport_unmap);
  98. mv_set(irq_demux);
  99. if (!sh_mv.mv_nr_irqs)
  100. sh_mv.mv_nr_irqs = NR_IRQS;
  101. }