env.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. int ret; \
  29. if (strncmp(option, (char *)p, strlen(option)) == 0) \
  30. ret = strict_strtol((char *)p + strlen(option"="), 10, &res); \
  31. } while (0)
  32. void __init prom_init_env(void)
  33. {
  34. /* pmon passes arguments in 32bit pointers */
  35. int *_prom_envp;
  36. unsigned long bus_clock;
  37. unsigned int processor_id;
  38. long l;
  39. /* firmware arguments are initialized in head.S */
  40. _prom_envp = (int *)fw_arg2;
  41. l = (long)*_prom_envp;
  42. while (l != 0) {
  43. parse_even_earlier(bus_clock, "busclock", l);
  44. parse_even_earlier(cpu_clock_freq, "cpuclock", l);
  45. parse_even_earlier(memsize, "memsize", l);
  46. parse_even_earlier(highmemsize, "highmemsize", l);
  47. _prom_envp++;
  48. l = (long)*_prom_envp;
  49. }
  50. if (memsize == 0)
  51. memsize = 256;
  52. if (bus_clock == 0)
  53. bus_clock = 66000000;
  54. if (cpu_clock_freq == 0) {
  55. processor_id = (&current_cpu_data)->processor_id;
  56. switch (processor_id & PRID_REV_MASK) {
  57. case PRID_REV_LOONGSON2E:
  58. cpu_clock_freq = 533080000;
  59. break;
  60. case PRID_REV_LOONGSON2F:
  61. cpu_clock_freq = 797000000;
  62. break;
  63. default:
  64. cpu_clock_freq = 100000000;
  65. break;
  66. }
  67. }
  68. pr_info("busclock=%ld, cpuclock=%ld, memsize=%ld, highmemsize=%ld\n",
  69. bus_clock, cpu_clock_freq, memsize, highmemsize);
  70. }