mips_machine.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published
  6. * by the Free Software Foundation.
  7. *
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/string.h>
  11. #include <linux/slab.h>
  12. #include <asm/mips_machine.h>
  13. static struct mips_machine *mips_machine __initdata;
  14. static char *mips_machine_name = "Unknown";
  15. #define for_each_machine(mach) \
  16. for ((mach) = (struct mips_machine *)&__mips_machines_start; \
  17. (mach) && \
  18. (unsigned long)(mach) < (unsigned long)&__mips_machines_end; \
  19. (mach)++)
  20. __init void mips_set_machine_name(const char *name)
  21. {
  22. char *p;
  23. if (name == NULL)
  24. return;
  25. p = kstrdup(name, GFP_KERNEL);
  26. if (!p)
  27. pr_err("MIPS: no memory for machine_name\n");
  28. mips_machine_name = p;
  29. }
  30. char *mips_get_machine_name(void)
  31. {
  32. return mips_machine_name;
  33. }
  34. __init int mips_machtype_setup(char *id)
  35. {
  36. struct mips_machine *mach;
  37. for_each_machine(mach) {
  38. if (mach->mach_id == NULL)
  39. continue;
  40. if (strcmp(mach->mach_id, id) == 0) {
  41. mips_machtype = mach->mach_type;
  42. return 0;
  43. }
  44. }
  45. pr_err("MIPS: no machine found for id '%s', supported machines:\n", id);
  46. pr_err("%-24s %s\n", "id", "name");
  47. for_each_machine(mach)
  48. pr_err("%-24s %s\n", mach->mach_id, mach->mach_name);
  49. return 1;
  50. }
  51. __setup("machtype=", mips_machtype_setup);
  52. __init void mips_machine_setup(void)
  53. {
  54. struct mips_machine *mach;
  55. for_each_machine(mach) {
  56. if (mips_machtype == mach->mach_type) {
  57. mips_machine = mach;
  58. break;
  59. }
  60. }
  61. if (!mips_machine)
  62. return;
  63. mips_set_machine_name(mips_machine->mach_name);
  64. pr_info("MIPS: machine is %s\n", mips_machine_name);
  65. if (mips_machine->mach_setup)
  66. mips_machine->mach_setup();
  67. }