machvec.c 3.3 KB
Newer Older
P
Paul Mundt 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * arch/sh/kernel/machvec.c
 *
 * The SuperH machine vector setup handlers, yanked from setup.c
 *
 *  Copyright (C) 1999  Niibe Yutaka
 *  Copyright (C) 2002 - 2007 Paul Mundt
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/init.h>
#include <linux/string.h>
#include <asm/machvec.h>
#include <asm/sections.h>
17
#include <asm/addrspace.h>
P
Paul Mundt 已提交
18
#include <asm/setup.h>
P
Paul Mundt 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <asm/io.h>
#include <asm/irq.h>

#define MV_NAME_SIZE 32

#define for_each_mv(mv) \
	for ((mv) = (struct sh_machine_vector *)&__machvec_start; \
	     (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \
	     (mv)++)

static struct sh_machine_vector * __init get_mv_byname(const char *name)
{
	struct sh_machine_vector *mv;

	for_each_mv(mv)
P
Paul Mundt 已提交
34
		if (strcasecmp(name, mv->mv_name) == 0)
P
Paul Mundt 已提交
35 36 37 38 39
			return mv;

	return NULL;
}

40 41
static unsigned int __initdata machvec_selected;

P
Paul Mundt 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
static int __init early_parse_mv(char *from)
{
	char mv_name[MV_NAME_SIZE] = "";
	char *mv_end;
	char *mv_comma;
	int mv_len;
	struct sh_machine_vector *mvp;

	mv_end = strchr(from, ' ');
	if (mv_end == NULL)
		mv_end = from + strlen(from);

	mv_comma = strchr(from, ',');
	mv_len = mv_end - from;
	if (mv_len > (MV_NAME_SIZE-1))
		mv_len = MV_NAME_SIZE-1;
	memcpy(mv_name, from, mv_len);
	mv_name[mv_len] = '\0';
	from = mv_end;

62 63 64 65 66 67
	machvec_selected = 1;

	/* Boot with the generic vector */
	if (strcmp(mv_name, "generic") == 0)
		return 0;

P
Paul Mundt 已提交
68 69
	mvp = get_mv_byname(mv_name);
	if (unlikely(!mvp)) {
70
		printk("Available vectors:\n\n\t'%s', ", sh_mv.mv_name);
P
Paul Mundt 已提交
71 72 73 74 75 76 77
		for_each_mv(mvp)
			printk("'%s', ", mvp->mv_name);
		printk("\n\n");
		panic("Failed to select machvec '%s' -- halting.\n",
		      mv_name);
	} else
		sh_mv = *mvp;
P
Paul Mundt 已提交
78 79 80 81 82 83 84

	return 0;
}
early_param("sh_mv", early_parse_mv);

void __init sh_mv_setup(void)
{
P
Paul Mundt 已提交
85 86 87 88
	/*
	 * Only overload the machvec if one hasn't been selected on
	 * the command line with sh_mv=
	 */
89
	if (!machvec_selected) {
P
Paul Mundt 已提交
90 91 92 93 94
		unsigned long machvec_size;

		machvec_size = ((unsigned long)&__machvec_end -
				(unsigned long)&__machvec_start);

95 96 97 98 99 100 101
		/*
		 * Sanity check for machvec section alignment. Ensure
		 * __initmv hasn't been misused.
		 */
		if (machvec_size % sizeof(struct sh_machine_vector))
			panic("machvec misaligned, invalid __initmv use?");

P
Paul Mundt 已提交
102 103 104 105 106 107 108 109 110 111
		/*
		 * If the machvec hasn't been preselected, use the first
		 * vector (usually the only one) from .machvec.init.
		 */
		if (machvec_size >= sizeof(struct sh_machine_vector))
			sh_mv = *(struct sh_machine_vector *)&__machvec_start;
	}

	printk(KERN_NOTICE "Booting machvec: %s\n", get_system_type());

P
Paul Mundt 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	/*
	 * Manually walk the vec, fill in anything that the board hasn't yet
	 * by hand, wrapping to the generic implementation.
	 */
#define mv_set(elem) do { \
	if (!sh_mv.mv_##elem) \
		sh_mv.mv_##elem = generic_##elem; \
} while (0)

	mv_set(inb);	mv_set(inw);	mv_set(inl);
	mv_set(outb);	mv_set(outw);	mv_set(outl);

	mv_set(inb_p);	mv_set(inw_p);	mv_set(inl_p);
	mv_set(outb_p);	mv_set(outw_p);	mv_set(outl_p);

	mv_set(insb);	mv_set(insw);	mv_set(insl);
	mv_set(outsb);	mv_set(outsw);	mv_set(outsl);

	mv_set(ioport_map);
	mv_set(ioport_unmap);
	mv_set(irq_demux);
133
	mv_set(mode_pins);
P
Paul Mundt 已提交
134 135 136

	if (!sh_mv.mv_nr_irqs)
		sh_mv.mv_nr_irqs = NR_IRQS;
137

138
#ifdef P2SEG
139
	__set_io_port_base(P2SEG);
140 141 142
#else
	__set_io_port_base(0);
#endif
P
Paul Mundt 已提交
143
}