generic: merge mips multi machine update to generic patches for 2.6.34
[openwrt/svn-archive/archive.git] / target / linux / generic-2.6 / patches-2.6.34 / 020-mips_multi_machine_support.patch
1 --- /dev/null
2 +++ b/arch/mips/include/asm/mips_machine.h
3 @@ -0,0 +1,54 @@
4 +/*
5 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
6 + *
7 + * This program is free software; you can redistribute it and/or modify it
8 + * under the terms of the GNU General Public License version 2 as published
9 + * by the Free Software Foundation.
10 + *
11 + */
12 +
13 +#ifndef __ASM_MIPS_MACHINE_H
14 +#define __ASM_MIPS_MACHINE_H
15 +
16 +#include <linux/init.h>
17 +#include <linux/list.h>
18 +
19 +#include <asm/bootinfo.h>
20 +
21 +struct mips_machine {
22 + unsigned long mach_type;
23 + const char *mach_id;
24 + const char *mach_name;
25 + void (*mach_setup)(void);
26 +};
27 +
28 +#define MIPS_MACHINE(_type, _id, _name, _setup) \
29 +static const char machine_name_##_type[] __initconst \
30 + __aligned(1) = _name; \
31 +static const char machine_id_##_type[] __initconst \
32 + __aligned(1) = _id; \
33 +static struct mips_machine machine_##_type \
34 + __used __section(.mips.machines.init) = \
35 +{ \
36 + .mach_type = _type, \
37 + .mach_id = machine_id_##_type, \
38 + .mach_name = machine_name_##_type, \
39 + .mach_setup = _setup, \
40 +};
41 +
42 +extern long __mips_machines_start;
43 +extern long __mips_machines_end;
44 +
45 +#ifdef CONFIG_MIPS_MACHINE
46 +int mips_machtype_setup(char *id) __init;
47 +void mips_machine_setup(void) __init;
48 +void mips_set_machine_name(const char *name) __init;
49 +char *mips_get_machine_name(void);
50 +#else
51 +static inline int mips_machtype_setup(char *id) { return 1; }
52 +static inline void mips_machine_setup(void) { }
53 +static inline void mips_set_machine_name(const char *name) { }
54 +static inline char *mips_get_machine_name(void) { return NULL; }
55 +#endif /* CONFIG_MIPS_MACHINE */
56 +
57 +#endif /* __ASM_MIPS_MACHINE_H */
58 --- /dev/null
59 +++ b/arch/mips/kernel/mips_machine.c
60 @@ -0,0 +1,83 @@
61 +/*
62 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
63 + *
64 + * This program is free software; you can redistribute it and/or modify it
65 + * under the terms of the GNU General Public License version 2 as published
66 + * by the Free Software Foundation.
67 + *
68 + */
69 +#include <linux/mm.h>
70 +#include <linux/string.h>
71 +#include <linux/slab.h>
72 +
73 +#include <asm/mips_machine.h>
74 +
75 +static struct mips_machine *mips_machine __initdata;
76 +static char *mips_machine_name = "Unknown";
77 +
78 +#define for_each_machine(mach) \
79 + for ((mach) = (struct mips_machine *)&__mips_machines_start; \
80 + (mach) && \
81 + (unsigned long)(mach) < (unsigned long)&__mips_machines_end; \
82 + (mach)++)
83 +
84 +__init void mips_set_machine_name(const char *name)
85 +{
86 + char *p;
87 +
88 + if (name == NULL)
89 + return;
90 +
91 + p = kstrdup(name, GFP_KERNEL);
92 + if (!p)
93 + pr_err("MIPS: no memory for machine_name\n");
94 +
95 + mips_machine_name = p;
96 +}
97 +
98 +char *mips_get_machine_name(void)
99 +{
100 + return mips_machine_name;
101 +}
102 +
103 +__init int mips_machtype_setup(char *id)
104 +{
105 + struct mips_machine *mach;
106 +
107 + for_each_machine(mach) {
108 + if (mach->mach_id == NULL)
109 + continue;
110 +
111 + if (strcmp(mach->mach_id, id) == 0) {
112 + mips_machine = mach;
113 + break;
114 + }
115 + }
116 +
117 + if (!mips_machine) {
118 + pr_err("MIPS: no machine found for id '%s', supported machines:\n",
119 + id);
120 + pr_err("%32s %s\n", "id", "name");
121 + for_each_machine(mach)
122 + pr_err("%32s %s\n", mach->mach_id, mach->mach_name);
123 + return 1;
124 + }
125 +
126 + mips_machtype = mips_machine->mach_type;
127 +
128 + return 0;
129 +}
130 +
131 +__setup("machtype=", mips_machtype_setup);
132 +
133 +__init void mips_machine_setup(void)
134 +{
135 + if (!mips_machine)
136 + return;
137 +
138 + mips_set_machine_name(mips_machine->mach_name);
139 + pr_info("MIPS: machine is %s\n", mips_machine_name);
140 +
141 + if (mips_machine->mach_setup)
142 + mips_machine->mach_setup();
143 +}
144 --- a/arch/mips/kernel/Makefile
145 +++ b/arch/mips/kernel/Makefile
146 @@ -94,6 +94,7 @@ obj-$(CONFIG_GPIO_TXX9) += gpio_txx9.o
147 obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
148 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
149 obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o
150 +obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o
151
152 CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
153
154 --- a/arch/mips/Kconfig
155 +++ b/arch/mips/Kconfig
156 @@ -853,6 +853,9 @@ config MIPS_DISABLE_OBSOLETE_IDE
157 config SYNC_R4K
158 bool
159
160 +config MIPS_MACHINE
161 + def_bool n
162 +
163 config NO_IOPORT
164 def_bool n
165
166 --- a/arch/mips/kernel/proc.c
167 +++ b/arch/mips/kernel/proc.c
168 @@ -12,6 +12,7 @@
169 #include <asm/cpu-features.h>
170 #include <asm/mipsregs.h>
171 #include <asm/processor.h>
172 +#include <asm/mips_machine.h>
173
174 unsigned int vced_count, vcei_count;
175
176 @@ -31,8 +32,12 @@ static int show_cpuinfo(struct seq_file
177 /*
178 * For the first processor also print the system type
179 */
180 - if (n == 0)
181 + if (n == 0) {
182 seq_printf(m, "system type\t\t: %s\n", get_system_type());
183 + if (mips_get_machine_name())
184 + seq_printf(m, "machine\t\t\t: %s\n",
185 + mips_get_machine_name());
186 + }
187
188 seq_printf(m, "processor\t\t: %ld\n", n);
189 sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n",
190 --- a/arch/mips/kernel/vmlinux.lds.S
191 +++ b/arch/mips/kernel/vmlinux.lds.S
192 @@ -98,6 +98,13 @@ SECTIONS
193 INIT_TEXT_SECTION(PAGE_SIZE)
194 INIT_DATA_SECTION(16)
195
196 + . = ALIGN(4);
197 + .mips.machines.init : AT(ADDR(.mips.machines.init) - LOAD_OFFSET) {
198 + __mips_machines_start = .;
199 + *(.mips.machines.init)
200 + __mips_machines_end = .;
201 + }
202 +
203 /* .exit.text is discarded at runtime, not link time, to deal with
204 * references from .rodata
205 */