15933f6d2SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
29655ad03SPaul Mundt /*
39655ad03SPaul Mundt * arch/sh/kernel/machvec.c
49655ad03SPaul Mundt *
59655ad03SPaul Mundt * The SuperH machine vector setup handlers, yanked from setup.c
69655ad03SPaul Mundt *
79655ad03SPaul Mundt * Copyright (C) 1999 Niibe Yutaka
89655ad03SPaul Mundt * Copyright (C) 2002 - 2007 Paul Mundt
99655ad03SPaul Mundt */
109655ad03SPaul Mundt #include <linux/init.h>
119655ad03SPaul Mundt #include <linux/string.h>
129655ad03SPaul Mundt #include <asm/machvec.h>
139655ad03SPaul Mundt #include <asm/sections.h>
14d44ee12aSPaul Mundt #include <asm/addrspace.h>
15fa43972fSPaul Mundt #include <asm/setup.h>
169655ad03SPaul Mundt #include <asm/io.h>
179655ad03SPaul Mundt #include <asm/irq.h>
180cd39f46SPeter Zijlstra #include <asm/processor.h>
199655ad03SPaul Mundt
209655ad03SPaul Mundt #define MV_NAME_SIZE 32
219655ad03SPaul Mundt
229655ad03SPaul Mundt #define for_each_mv(mv) \
23*c5783af3SKees Cook for ((mv) = (struct sh_machine_vector *)__machvec_start; \
24*c5783af3SKees Cook (mv) && (unsigned long)(mv) < (unsigned long)__machvec_end; \
259655ad03SPaul Mundt (mv)++)
269655ad03SPaul Mundt
get_mv_byname(const char * name)279655ad03SPaul Mundt static struct sh_machine_vector * __init get_mv_byname(const char *name)
289655ad03SPaul Mundt {
299655ad03SPaul Mundt struct sh_machine_vector *mv;
309655ad03SPaul Mundt
319655ad03SPaul Mundt for_each_mv(mv)
3282f81f47SPaul Mundt if (strcasecmp(name, mv->mv_name) == 0)
339655ad03SPaul Mundt return mv;
349655ad03SPaul Mundt
359655ad03SPaul Mundt return NULL;
369655ad03SPaul Mundt }
379655ad03SPaul Mundt
38fd8f20e8SPaul Mundt static unsigned int __initdata machvec_selected;
39fd8f20e8SPaul Mundt
early_parse_mv(char * from)409655ad03SPaul Mundt static int __init early_parse_mv(char *from)
419655ad03SPaul Mundt {
429655ad03SPaul Mundt char mv_name[MV_NAME_SIZE] = "";
439655ad03SPaul Mundt char *mv_end;
449655ad03SPaul Mundt char *mv_comma;
459655ad03SPaul Mundt int mv_len;
469655ad03SPaul Mundt struct sh_machine_vector *mvp;
479655ad03SPaul Mundt
489655ad03SPaul Mundt mv_end = strchr(from, ' ');
499655ad03SPaul Mundt if (mv_end == NULL)
509655ad03SPaul Mundt mv_end = from + strlen(from);
519655ad03SPaul Mundt
529655ad03SPaul Mundt mv_comma = strchr(from, ',');
539655ad03SPaul Mundt mv_len = mv_end - from;
549655ad03SPaul Mundt if (mv_len > (MV_NAME_SIZE-1))
559655ad03SPaul Mundt mv_len = MV_NAME_SIZE-1;
569655ad03SPaul Mundt memcpy(mv_name, from, mv_len);
579655ad03SPaul Mundt mv_name[mv_len] = '\0';
589655ad03SPaul Mundt from = mv_end;
599655ad03SPaul Mundt
60fd8f20e8SPaul Mundt machvec_selected = 1;
61fd8f20e8SPaul Mundt
62fd8f20e8SPaul Mundt /* Boot with the generic vector */
63fd8f20e8SPaul Mundt if (strcmp(mv_name, "generic") == 0)
64fd8f20e8SPaul Mundt return 0;
65fd8f20e8SPaul Mundt
669655ad03SPaul Mundt mvp = get_mv_byname(mv_name);
679655ad03SPaul Mundt if (unlikely(!mvp)) {
68eac1a488SGeert Uytterhoeven pr_info("Available vectors:\n\n\t'%s', ", sh_mv.mv_name);
699655ad03SPaul Mundt for_each_mv(mvp)
70eac1a488SGeert Uytterhoeven pr_cont("'%s', ", mvp->mv_name);
71eac1a488SGeert Uytterhoeven pr_cont("\n\n");
729655ad03SPaul Mundt panic("Failed to select machvec '%s' -- halting.\n",
739655ad03SPaul Mundt mv_name);
749655ad03SPaul Mundt } else
759655ad03SPaul Mundt sh_mv = *mvp;
769655ad03SPaul Mundt
779655ad03SPaul Mundt return 0;
789655ad03SPaul Mundt }
799655ad03SPaul Mundt early_param("sh_mv", early_parse_mv);
809655ad03SPaul Mundt
sh_mv_setup(void)819655ad03SPaul Mundt void __init sh_mv_setup(void)
829655ad03SPaul Mundt {
839655ad03SPaul Mundt /*
8482f81f47SPaul Mundt * Only overload the machvec if one hasn't been selected on
8582f81f47SPaul Mundt * the command line with sh_mv=
8682f81f47SPaul Mundt */
87fd8f20e8SPaul Mundt if (!machvec_selected) {
8882f81f47SPaul Mundt unsigned long machvec_size;
8982f81f47SPaul Mundt
90*c5783af3SKees Cook machvec_size = ((unsigned long)__machvec_end -
91*c5783af3SKees Cook (unsigned long)__machvec_start);
9282f81f47SPaul Mundt
9382f81f47SPaul Mundt /*
945556410eSPaul Mundt * Sanity check for machvec section alignment. Ensure
955556410eSPaul Mundt * __initmv hasn't been misused.
965556410eSPaul Mundt */
975556410eSPaul Mundt if (machvec_size % sizeof(struct sh_machine_vector))
985556410eSPaul Mundt panic("machvec misaligned, invalid __initmv use?");
995556410eSPaul Mundt
1005556410eSPaul Mundt /*
10182f81f47SPaul Mundt * If the machvec hasn't been preselected, use the first
10282f81f47SPaul Mundt * vector (usually the only one) from .machvec.init.
10382f81f47SPaul Mundt */
10482f81f47SPaul Mundt if (machvec_size >= sizeof(struct sh_machine_vector))
105*c5783af3SKees Cook sh_mv = *(struct sh_machine_vector *)__machvec_start;
10682f81f47SPaul Mundt }
10782f81f47SPaul Mundt
108eac1a488SGeert Uytterhoeven pr_notice("Booting machvec: %s\n", get_system_type());
10982f81f47SPaul Mundt
11082f81f47SPaul Mundt /*
1119655ad03SPaul Mundt * Manually walk the vec, fill in anything that the board hasn't yet
1129655ad03SPaul Mundt * by hand, wrapping to the generic implementation.
1139655ad03SPaul Mundt */
1149655ad03SPaul Mundt #define mv_set(elem) do { \
1159655ad03SPaul Mundt if (!sh_mv.mv_##elem) \
1169655ad03SPaul Mundt sh_mv.mv_##elem = generic_##elem; \
1179655ad03SPaul Mundt } while (0)
1189655ad03SPaul Mundt
1199655ad03SPaul Mundt mv_set(irq_demux);
120eb9b9b56SMagnus Damm mv_set(mode_pins);
12119d8f84fSPaul Mundt mv_set(mem_init);
1229655ad03SPaul Mundt }
123