env.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Based on Ocelot Linux port, which is
  3. * Copyright 2001 MontaVista Software Inc.
  4. * Author: jsun@mvista.com or jsun@junsun.net
  5. *
  6. * Copyright 2003 ICT CAS
  7. * Author: Michael Guo <guoyi@ict.ac.cn>
  8. *
  9. * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  10. * Author: Fuxin Zhang, zhangfx@lemote.com
  11. *
  12. * Copyright (C) 2009 Lemote Inc.
  13. * Author: Wu Zhangjin, wuzhangjin@gmail.com
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. */
  20. #include <linux/module.h>
  21. #include <asm/bootinfo.h>
  22. #include <loongson.h>
  23. unsigned long cpu_clock_freq;
  24. EXPORT_SYMBOL(cpu_clock_freq);
  25. unsigned long memsize, highmemsize;
  26. #define parse_even_earlier(res, option, p) \
  27. do { \
  28. unsigned int tmp __maybe_unused; \
  29. \
  30. if (strncmp(option, (char *)p, strlen(option)) == 0) \
  31. tmp = strict_strtol((char *)p + strlen(option"="), 10, &res); \
  32. } while (0)
  33. void __init prom_init_env(void)
  34. {
  35. /* pmon passes arguments in 32bit pointers */
  36. int *_prom_envp;
  37. unsigned long bus_clock;
  38. unsigned int processor_id;
  39. long l;
  40. /* firmware arguments are initialized in head.S */
  41. _prom_envp = (int *)fw_arg2;
  42. l = (long)*_prom_envp;
  43. while (l != 0) {
  44. parse_even_earlier(bus_clock, "busclock", l);
  45. parse_even_earlier(cpu_clock_freq, "cpuclock", l);
  46. parse_even_earlier(memsize, "memsize", l);
  47. parse_even_earlier(highmemsize, "highmemsize", l);
  48. _prom_envp++;
  49. l = (long)*_prom_envp;
  50. }
  51. if (memsize == 0)
  52. memsize = 256;
  53. if (bus_clock == 0)
  54. bus_clock = 66000000;
  55. if (cpu_clock_freq == 0) {
  56. processor_id = (&current_cpu_data)->processor_id;
  57. switch (processor_id & PRID_REV_MASK) {
  58. case PRID_REV_LOONGSON2E:
  59. cpu_clock_freq = 533080000;
  60. break;
  61. case PRID_REV_LOONGSON2F:
  62. cpu_clock_freq = 797000000;
  63. break;
  64. default:
  65. cpu_clock_freq = 100000000;
  66. break;
  67. }
  68. }
  69. pr_info("busclock=%ld, cpuclock=%ld, memsize=%ld, highmemsize=%ld\n",
  70. bus_clock, cpu_clock_freq, memsize, highmemsize);
  71. }