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