2 +++ b/arch/mips/include/asm/mips_machine.h
5 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
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.
13 +#ifndef __ASM_MIPS_MACHINE_H
14 +#define __ASM_MIPS_MACHINE_H
16 +#include <linux/init.h>
17 +#include <linux/list.h>
19 +#include <asm/bootinfo.h>
21 +struct mips_machine {
22 + unsigned long mach_type;
23 + const char *mach_id;
24 + const char *mach_name;
25 + void (*mach_setup)(void);
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) = \
36 + .mach_type = _type, \
37 + .mach_id = machine_id_##_type, \
38 + .mach_name = machine_name_##_type, \
39 + .mach_setup = _setup, \
42 +extern long __mips_machines_start;
43 +extern long __mips_machines_end;
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);
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 */
57 +#endif /* __ASM_MIPS_MACHINE_H */
59 +++ b/arch/mips/kernel/mips_machine.c
62 + * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
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.
69 +#include <linux/mm.h>
70 +#include <linux/string.h>
71 +#include <linux/slab.h>
73 +#include <asm/mips_machine.h>
75 +static struct mips_machine *mips_machine __initdata;
76 +static char *mips_machine_name = "Unknown";
78 +#define for_each_machine(mach) \
79 + for ((mach) = (struct mips_machine *)&__mips_machines_start; \
81 + (unsigned long)(mach) < (unsigned long)&__mips_machines_end; \
84 +__init void mips_set_machine_name(const char *name)
91 + p = kstrdup(name, GFP_KERNEL);
93 + pr_err("MIPS: no memory for machine_name\n");
95 + mips_machine_name = p;
98 +char *mips_get_machine_name(void)
100 + return mips_machine_name;
103 +__init int mips_machtype_setup(char *id)
105 + struct mips_machine *mach;
107 + for_each_machine(mach) {
108 + if (mach->mach_id == NULL)
111 + if (strcmp(mach->mach_id, id) == 0) {
112 + mips_machtype = mach->mach_type;
117 + pr_err("MIPS: no machine found for id '%s', supported machines:\n", id);
118 + pr_err("%-24s : %s\n", "id", "name");
119 + for_each_machine(mach)
120 + pr_err("%-24s : %s\n", mach->mach_id, mach->mach_name);
125 +__setup("machtype=", mips_machtype_setup);
127 +__init void mips_machine_setup(void)
129 + struct mips_machine *mach;
131 + for_each_machine(mach) {
132 + if (mips_machtype == mach->mach_type) {
133 + mips_machine = mach;
141 + mips_set_machine_name(mips_machine->mach_name);
142 + pr_info("MIPS: machine is %s\n", mips_machine_name);
144 + if (mips_machine->mach_setup)
145 + mips_machine->mach_setup();
147 --- a/arch/mips/kernel/Makefile
148 +++ b/arch/mips/kernel/Makefile
149 @@ -93,6 +93,7 @@ obj-$(CONFIG_GPIO_TXX9) += gpio_txx9.o
151 obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
152 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
153 +obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o
155 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)
157 --- a/arch/mips/Kconfig
158 +++ b/arch/mips/Kconfig
159 @@ -851,6 +851,9 @@ config MIPS_DISABLE_OBSOLETE_IDE
169 --- a/arch/mips/kernel/proc.c
170 +++ b/arch/mips/kernel/proc.c
172 #include <asm/cpu-features.h>
173 #include <asm/mipsregs.h>
174 #include <asm/processor.h>
175 +#include <asm/mips_machine.h>
177 unsigned int vced_count, vcei_count;
179 @@ -31,8 +32,12 @@ static int show_cpuinfo(struct seq_file
181 * For the first processor also print the system type
185 seq_printf(m, "system type\t\t: %s\n", get_system_type());
186 + if (mips_get_machine_name())
187 + seq_printf(m, "machine\t\t\t: %s\n",
188 + mips_get_machine_name());
191 seq_printf(m, "processor\t\t: %ld\n", n);
192 sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n",
193 --- a/arch/mips/kernel/vmlinux.lds.S
194 +++ b/arch/mips/kernel/vmlinux.lds.S
195 @@ -98,6 +98,13 @@ SECTIONS
196 INIT_TEXT_SECTION(PAGE_SIZE)
197 INIT_DATA_SECTION(16)
200 + .mips.machines.init : AT(ADDR(.mips.machines.init) - LOAD_OFFSET) {
201 + __mips_machines_start = .;
202 + *(.mips.machines.init)
203 + __mips_machines_end = .;
206 /* .exit.text is discarded at runtime, not link time, to deal with
207 * references from .rodata