blob: d606679a211e1bdb4095faf46523d0c562155cef [file] [log] [blame]
Kuninori Morimoto5933f6d2018-12-28 00:32:24 -08001// SPDX-License-Identifier: GPL-2.0
Paul Mundt9655ad02007-05-14 15:59:09 +09002/*
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
Paul Mundt9655ad02007-05-14 15:59:09 +09009 */
10#include <linux/init.h>
11#include <linux/string.h>
12#include <asm/machvec.h>
13#include <asm/sections.h>
Paul Mundtd44ee122009-09-28 15:05:41 +090014#include <asm/addrspace.h>
Paul Mundtfa439722008-09-04 18:53:58 +090015#include <asm/setup.h>
Paul Mundt9655ad02007-05-14 15:59:09 +090016#include <asm/io.h>
17#include <asm/irq.h>
Peter Zijlstra0cd39f42020-08-06 14:35:11 +020018#include <asm/processor.h>
Paul Mundt9655ad02007-05-14 15:59:09 +090019
20#define MV_NAME_SIZE 32
21
22#define for_each_mv(mv) \
23 for ((mv) = (struct sh_machine_vector *)&__machvec_start; \
24 (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \
25 (mv)++)
26
27static struct sh_machine_vector * __init get_mv_byname(const char *name)
28{
29 struct sh_machine_vector *mv;
30
31 for_each_mv(mv)
Paul Mundt82f81f42007-05-15 15:19:34 +090032 if (strcasecmp(name, mv->mv_name) == 0)
Paul Mundt9655ad02007-05-14 15:59:09 +090033 return mv;
34
35 return NULL;
36}
37
Paul Mundtfd8f20e2007-05-15 15:38:30 +090038static unsigned int __initdata machvec_selected;
39
Paul Mundt9655ad02007-05-14 15:59:09 +090040static int __init early_parse_mv(char *from)
41{
42 char mv_name[MV_NAME_SIZE] = "";
43 char *mv_end;
44 char *mv_comma;
45 int mv_len;
46 struct sh_machine_vector *mvp;
47
48 mv_end = strchr(from, ' ');
49 if (mv_end == NULL)
50 mv_end = from + strlen(from);
51
52 mv_comma = strchr(from, ',');
53 mv_len = mv_end - from;
54 if (mv_len > (MV_NAME_SIZE-1))
55 mv_len = MV_NAME_SIZE-1;
56 memcpy(mv_name, from, mv_len);
57 mv_name[mv_len] = '\0';
58 from = mv_end;
59
Paul Mundtfd8f20e2007-05-15 15:38:30 +090060 machvec_selected = 1;
61
62 /* Boot with the generic vector */
63 if (strcmp(mv_name, "generic") == 0)
64 return 0;
65
Paul Mundt82f81f42007-05-15 15:19:34 +090066 mvp = get_mv_byname(mv_name);
67 if (unlikely(!mvp)) {
Geert Uytterhoeveneac1a482020-06-17 16:36:39 +020068 pr_info("Available vectors:\n\n\t'%s', ", sh_mv.mv_name);
Paul Mundt82f81f42007-05-15 15:19:34 +090069 for_each_mv(mvp)
Geert Uytterhoeveneac1a482020-06-17 16:36:39 +020070 pr_cont("'%s', ", mvp->mv_name);
71 pr_cont("\n\n");
Paul Mundt82f81f42007-05-15 15:19:34 +090072 panic("Failed to select machvec '%s' -- halting.\n",
73 mv_name);
74 } else
75 sh_mv = *mvp;
Paul Mundt9655ad02007-05-14 15:59:09 +090076
Paul Mundt9655ad02007-05-14 15:59:09 +090077 return 0;
78}
79early_param("sh_mv", early_parse_mv);
80
81void __init sh_mv_setup(void)
82{
83 /*
Paul Mundt82f81f42007-05-15 15:19:34 +090084 * Only overload the machvec if one hasn't been selected on
85 * the command line with sh_mv=
86 */
Paul Mundtfd8f20e2007-05-15 15:38:30 +090087 if (!machvec_selected) {
Paul Mundt82f81f42007-05-15 15:19:34 +090088 unsigned long machvec_size;
89
90 machvec_size = ((unsigned long)&__machvec_end -
91 (unsigned long)&__machvec_start);
92
93 /*
Paul Mundt55564102007-08-07 19:13:23 +090094 * Sanity check for machvec section alignment. Ensure
95 * __initmv hasn't been misused.
96 */
97 if (machvec_size % sizeof(struct sh_machine_vector))
98 panic("machvec misaligned, invalid __initmv use?");
99
100 /*
Paul Mundt82f81f42007-05-15 15:19:34 +0900101 * If the machvec hasn't been preselected, use the first
102 * vector (usually the only one) from .machvec.init.
103 */
104 if (machvec_size >= sizeof(struct sh_machine_vector))
105 sh_mv = *(struct sh_machine_vector *)&__machvec_start;
106 }
107
Geert Uytterhoeveneac1a482020-06-17 16:36:39 +0200108 pr_notice("Booting machvec: %s\n", get_system_type());
Paul Mundt82f81f42007-05-15 15:19:34 +0900109
110 /*
Paul Mundt9655ad02007-05-14 15:59:09 +0900111 * Manually walk the vec, fill in anything that the board hasn't yet
112 * by hand, wrapping to the generic implementation.
113 */
114#define mv_set(elem) do { \
115 if (!sh_mv.mv_##elem) \
116 sh_mv.mv_##elem = generic_##elem; \
117} while (0)
118
Paul Mundt9655ad02007-05-14 15:59:09 +0900119 mv_set(irq_demux);
Magnus Dammeb9b9b52009-05-28 11:51:51 +0000120 mv_set(mode_pins);
Paul Mundt19d8f842010-05-10 15:39:05 +0900121 mv_set(mem_init);
Paul Mundt9655ad02007-05-14 15:59:09 +0900122}