030-mips_multi_machine_support.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <[email protected]>
  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,86 @@
  61. +/*
  62. + * Copyright (C) 2008-2010 Gabor Juhos <[email protected]>
  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_machtype = mach->mach_type;
  113. + return 0;
  114. + }
  115. + }
  116. +
  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);
  121. +
  122. + return 1;
  123. +}
  124. +
  125. +__setup("machtype=", mips_machtype_setup);
  126. +
  127. +__init void mips_machine_setup(void)
  128. +{
  129. + struct mips_machine *mach;
  130. +
  131. + for_each_machine(mach) {
  132. + if (mips_machtype == mach->mach_type) {
  133. + mips_machine = mach;
  134. + break;
  135. + }
  136. + }
  137. +
  138. + if (!mips_machine)
  139. + return;
  140. +
  141. + mips_set_machine_name(mips_machine->mach_name);
  142. + pr_info("MIPS: machine is %s\n", mips_machine_name);
  143. +
  144. + if (mips_machine->mach_setup)
  145. + mips_machine->mach_setup();
  146. +}
  147. --- a/arch/mips/kernel/Makefile
  148. +++ b/arch/mips/kernel/Makefile
  149. @@ -95,6 +95,7 @@ obj-$(CONFIG_GPIO_TXX9) += gpio_txx9.o
  150. obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
  151. obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
  152. obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o
  153. +obj-$(CONFIG_MIPS_MACHINE) += mips_machine.o
  154. obj-$(CONFIG_OF) += prom.o
  155. --- a/arch/mips/Kconfig
  156. +++ b/arch/mips/Kconfig
  157. @@ -883,6 +883,9 @@ config MIPS_DISABLE_OBSOLETE_IDE
  158. config SYNC_R4K
  159. bool
  160. +config MIPS_MACHINE
  161. + def_bool n
  162. +
  163. config NO_IOPORT
  164. def_bool n
  165. --- a/arch/mips/kernel/proc.c
  166. +++ b/arch/mips/kernel/proc.c
  167. @@ -12,6 +12,7 @@
  168. #include <asm/cpu-features.h>
  169. #include <asm/mipsregs.h>
  170. #include <asm/processor.h>
  171. +#include <asm/mips_machine.h>
  172. unsigned int vced_count, vcei_count;
  173. @@ -31,8 +32,12 @@ static int show_cpuinfo(struct seq_file
  174. /*
  175. * For the first processor also print the system type
  176. */
  177. - if (n == 0)
  178. + if (n == 0) {
  179. seq_printf(m, "system type\t\t: %s\n", get_system_type());
  180. + if (mips_get_machine_name())
  181. + seq_printf(m, "machine\t\t\t: %s\n",
  182. + mips_get_machine_name());
  183. + }
  184. seq_printf(m, "processor\t\t: %ld\n", n);
  185. sprintf(fmt, "cpu model\t\t: %%s V%%d.%%d%s\n",
  186. --- a/arch/mips/kernel/vmlinux.lds.S
  187. +++ b/arch/mips/kernel/vmlinux.lds.S
  188. @@ -98,6 +98,13 @@ SECTIONS
  189. INIT_TEXT_SECTION(PAGE_SIZE)
  190. INIT_DATA_SECTION(16)
  191. + . = ALIGN(4);
  192. + .mips.machines.init : AT(ADDR(.mips.machines.init) - LOAD_OFFSET) {
  193. + __mips_machines_start = .;
  194. + *(.mips.machines.init)
  195. + __mips_machines_end = .;
  196. + }
  197. +
  198. /* .exit.text is discarded at runtime, not link time, to deal with
  199. * references from .rodata
  200. */