Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 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> |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 17 | #include <asm/setup.h> |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/irq.h> |
| 20 | |
| 21 | #define MV_NAME_SIZE 32 |
| 22 | |
| 23 | #define for_each_mv(mv) \ |
| 24 | for ((mv) = (struct sh_machine_vector *)&__machvec_start; \ |
| 25 | (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \ |
| 26 | (mv)++) |
| 27 | |
| 28 | static struct sh_machine_vector * __init get_mv_byname(const char *name) |
| 29 | { |
| 30 | struct sh_machine_vector *mv; |
| 31 | |
| 32 | for_each_mv(mv) |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 33 | if (strcasecmp(name, mv->mv_name) == 0) |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 34 | return mv; |
| 35 | |
| 36 | return NULL; |
| 37 | } |
| 38 | |
Paul Mundt | fd8f20e | 2007-05-15 15:38:30 +0900 | [diff] [blame] | 39 | static unsigned int __initdata machvec_selected; |
| 40 | |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 41 | static int __init early_parse_mv(char *from) |
| 42 | { |
| 43 | char mv_name[MV_NAME_SIZE] = ""; |
| 44 | char *mv_end; |
| 45 | char *mv_comma; |
| 46 | int mv_len; |
| 47 | struct sh_machine_vector *mvp; |
| 48 | |
| 49 | mv_end = strchr(from, ' '); |
| 50 | if (mv_end == NULL) |
| 51 | mv_end = from + strlen(from); |
| 52 | |
| 53 | mv_comma = strchr(from, ','); |
| 54 | mv_len = mv_end - from; |
| 55 | if (mv_len > (MV_NAME_SIZE-1)) |
| 56 | mv_len = MV_NAME_SIZE-1; |
| 57 | memcpy(mv_name, from, mv_len); |
| 58 | mv_name[mv_len] = '\0'; |
| 59 | from = mv_end; |
| 60 | |
Paul Mundt | fd8f20e | 2007-05-15 15:38:30 +0900 | [diff] [blame] | 61 | machvec_selected = 1; |
| 62 | |
| 63 | /* Boot with the generic vector */ |
| 64 | if (strcmp(mv_name, "generic") == 0) |
| 65 | return 0; |
| 66 | |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 67 | mvp = get_mv_byname(mv_name); |
| 68 | if (unlikely(!mvp)) { |
Paul Mundt | fd8f20e | 2007-05-15 15:38:30 +0900 | [diff] [blame] | 69 | printk("Available vectors:\n\n\t'%s', ", sh_mv.mv_name); |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 70 | for_each_mv(mvp) |
| 71 | printk("'%s', ", mvp->mv_name); |
| 72 | printk("\n\n"); |
| 73 | panic("Failed to select machvec '%s' -- halting.\n", |
| 74 | mv_name); |
| 75 | } else |
| 76 | sh_mv = *mvp; |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 77 | |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | early_param("sh_mv", early_parse_mv); |
| 81 | |
| 82 | void __init sh_mv_setup(void) |
| 83 | { |
| 84 | /* |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 85 | * Only overload the machvec if one hasn't been selected on |
| 86 | * the command line with sh_mv= |
| 87 | */ |
Paul Mundt | fd8f20e | 2007-05-15 15:38:30 +0900 | [diff] [blame] | 88 | if (!machvec_selected) { |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 89 | unsigned long machvec_size; |
| 90 | |
| 91 | machvec_size = ((unsigned long)&__machvec_end - |
| 92 | (unsigned long)&__machvec_start); |
| 93 | |
| 94 | /* |
Paul Mundt | 5556410 | 2007-08-07 19:13:23 +0900 | [diff] [blame] | 95 | * Sanity check for machvec section alignment. Ensure |
| 96 | * __initmv hasn't been misused. |
| 97 | */ |
| 98 | if (machvec_size % sizeof(struct sh_machine_vector)) |
| 99 | panic("machvec misaligned, invalid __initmv use?"); |
| 100 | |
| 101 | /* |
Paul Mundt | 82f81f4 | 2007-05-15 15:19:34 +0900 | [diff] [blame] | 102 | * If the machvec hasn't been preselected, use the first |
| 103 | * vector (usually the only one) from .machvec.init. |
| 104 | */ |
| 105 | if (machvec_size >= sizeof(struct sh_machine_vector)) |
| 106 | sh_mv = *(struct sh_machine_vector *)&__machvec_start; |
| 107 | } |
| 108 | |
| 109 | printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type()); |
| 110 | |
| 111 | /* |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 112 | * Manually walk the vec, fill in anything that the board hasn't yet |
| 113 | * by hand, wrapping to the generic implementation. |
| 114 | */ |
| 115 | #define mv_set(elem) do { \ |
| 116 | if (!sh_mv.mv_##elem) \ |
| 117 | sh_mv.mv_##elem = generic_##elem; \ |
| 118 | } while (0) |
| 119 | |
| 120 | mv_set(inb); mv_set(inw); mv_set(inl); |
| 121 | mv_set(outb); mv_set(outw); mv_set(outl); |
| 122 | |
| 123 | mv_set(inb_p); mv_set(inw_p); mv_set(inl_p); |
| 124 | mv_set(outb_p); mv_set(outw_p); mv_set(outl_p); |
| 125 | |
| 126 | mv_set(insb); mv_set(insw); mv_set(insl); |
| 127 | mv_set(outsb); mv_set(outsw); mv_set(outsl); |
| 128 | |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 129 | mv_set(ioport_map); |
| 130 | mv_set(ioport_unmap); |
| 131 | mv_set(irq_demux); |
Magnus Damm | eb9b9b5 | 2009-05-28 11:51:51 +0000 | [diff] [blame^] | 132 | mv_set(mode_pins); |
Paul Mundt | 9655ad0 | 2007-05-14 15:59:09 +0900 | [diff] [blame] | 133 | |
| 134 | if (!sh_mv.mv_nr_irqs) |
| 135 | sh_mv.mv_nr_irqs = NR_IRQS; |
| 136 | } |