env.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. & Institute 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. #include <boot_param.h>
  24. #include <workarounds.h>
  25. u32 cpu_clock_freq;
  26. EXPORT_SYMBOL(cpu_clock_freq);
  27. struct efi_memory_map_loongson *loongson_memmap;
  28. struct loongson_system_configuration loongson_sysconf;
  29. u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
  30. u64 loongson_chiptemp[MAX_PACKAGES];
  31. u64 loongson_freqctrl[MAX_PACKAGES];
  32. unsigned long long smp_group[4];
  33. #define parse_even_earlier(res, option, p) \
  34. do { \
  35. unsigned int tmp __maybe_unused; \
  36. \
  37. if (strncmp(option, (char *)p, strlen(option)) == 0) \
  38. tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \
  39. } while (0)
  40. void __init prom_init_env(void)
  41. {
  42. /* pmon passes arguments in 32bit pointers */
  43. unsigned int processor_id;
  44. #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
  45. int *_prom_envp;
  46. long l;
  47. /* firmware arguments are initialized in head.S */
  48. _prom_envp = (int *)fw_arg2;
  49. l = (long)*_prom_envp;
  50. while (l != 0) {
  51. parse_even_earlier(cpu_clock_freq, "cpuclock", l);
  52. parse_even_earlier(memsize, "memsize", l);
  53. parse_even_earlier(highmemsize, "highmemsize", l);
  54. _prom_envp++;
  55. l = (long)*_prom_envp;
  56. }
  57. if (memsize == 0)
  58. memsize = 256;
  59. loongson_sysconf.nr_uarts = 1;
  60. pr_info("memsize=%u, highmemsize=%u\n", memsize, highmemsize);
  61. #else
  62. struct boot_params *boot_p;
  63. struct loongson_params *loongson_p;
  64. struct system_loongson *esys;
  65. struct efi_cpuinfo_loongson *ecpu;
  66. struct irq_source_routing_table *eirq_source;
  67. /* firmware arguments are initialized in head.S */
  68. boot_p = (struct boot_params *)fw_arg2;
  69. loongson_p = &(boot_p->efi.smbios.lp);
  70. esys = (struct system_loongson *)
  71. ((u64)loongson_p + loongson_p->system_offset);
  72. ecpu = (struct efi_cpuinfo_loongson *)
  73. ((u64)loongson_p + loongson_p->cpu_offset);
  74. eirq_source = (struct irq_source_routing_table *)
  75. ((u64)loongson_p + loongson_p->irq_offset);
  76. loongson_memmap = (struct efi_memory_map_loongson *)
  77. ((u64)loongson_p + loongson_p->memory_offset);
  78. cpu_clock_freq = ecpu->cpu_clock_freq;
  79. loongson_sysconf.cputype = ecpu->cputype;
  80. if (ecpu->cputype == Loongson_3A) {
  81. loongson_sysconf.cores_per_node = 4;
  82. loongson_sysconf.cores_per_package = 4;
  83. smp_group[0] = 0x900000003ff01000;
  84. smp_group[1] = 0x900010003ff01000;
  85. smp_group[2] = 0x900020003ff01000;
  86. smp_group[3] = 0x900030003ff01000;
  87. loongson_chipcfg[0] = 0x900000001fe00180;
  88. loongson_chipcfg[1] = 0x900010001fe00180;
  89. loongson_chipcfg[2] = 0x900020001fe00180;
  90. loongson_chipcfg[3] = 0x900030001fe00180;
  91. loongson_chiptemp[0] = 0x900000001fe0019c;
  92. loongson_chiptemp[1] = 0x900010001fe0019c;
  93. loongson_chiptemp[2] = 0x900020001fe0019c;
  94. loongson_chiptemp[3] = 0x900030001fe0019c;
  95. loongson_freqctrl[0] = 0x900000001fe001d0;
  96. loongson_freqctrl[1] = 0x900010001fe001d0;
  97. loongson_freqctrl[2] = 0x900020001fe001d0;
  98. loongson_freqctrl[3] = 0x900030001fe001d0;
  99. loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
  100. loongson_sysconf.workarounds = WORKAROUND_CPUFREQ;
  101. } else if (ecpu->cputype == Loongson_3B) {
  102. loongson_sysconf.cores_per_node = 4; /* One chip has 2 nodes */
  103. loongson_sysconf.cores_per_package = 8;
  104. smp_group[0] = 0x900000003ff01000;
  105. smp_group[1] = 0x900010003ff05000;
  106. smp_group[2] = 0x900020003ff09000;
  107. smp_group[3] = 0x900030003ff0d000;
  108. loongson_chipcfg[0] = 0x900000001fe00180;
  109. loongson_chipcfg[1] = 0x900020001fe00180;
  110. loongson_chipcfg[2] = 0x900040001fe00180;
  111. loongson_chipcfg[3] = 0x900060001fe00180;
  112. loongson_chiptemp[0] = 0x900000001fe0019c;
  113. loongson_chiptemp[1] = 0x900020001fe0019c;
  114. loongson_chiptemp[2] = 0x900040001fe0019c;
  115. loongson_chiptemp[3] = 0x900060001fe0019c;
  116. loongson_freqctrl[0] = 0x900000001fe001d0;
  117. loongson_freqctrl[1] = 0x900020001fe001d0;
  118. loongson_freqctrl[2] = 0x900040001fe001d0;
  119. loongson_freqctrl[3] = 0x900060001fe001d0;
  120. loongson_sysconf.ht_control_base = 0x90001EFDFB000000;
  121. loongson_sysconf.workarounds = WORKAROUND_CPUHOTPLUG;
  122. } else {
  123. loongson_sysconf.cores_per_node = 1;
  124. loongson_sysconf.cores_per_package = 1;
  125. loongson_chipcfg[0] = 0x900000001fe00180;
  126. }
  127. loongson_sysconf.nr_cpus = ecpu->nr_cpus;
  128. loongson_sysconf.boot_cpu_id = ecpu->cpu_startup_core_id;
  129. loongson_sysconf.reserved_cpus_mask = ecpu->reserved_cores_mask;
  130. if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0)
  131. loongson_sysconf.nr_cpus = NR_CPUS;
  132. loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus +
  133. loongson_sysconf.cores_per_node - 1) /
  134. loongson_sysconf.cores_per_node;
  135. loongson_sysconf.pci_mem_start_addr = eirq_source->pci_mem_start_addr;
  136. loongson_sysconf.pci_mem_end_addr = eirq_source->pci_mem_end_addr;
  137. loongson_sysconf.pci_io_base = eirq_source->pci_io_start_addr;
  138. loongson_sysconf.dma_mask_bits = eirq_source->dma_mask_bits;
  139. if (loongson_sysconf.dma_mask_bits < 32 ||
  140. loongson_sysconf.dma_mask_bits > 64)
  141. loongson_sysconf.dma_mask_bits = 32;
  142. loongson_sysconf.restart_addr = boot_p->reset_system.ResetWarm;
  143. loongson_sysconf.poweroff_addr = boot_p->reset_system.Shutdown;
  144. loongson_sysconf.suspend_addr = boot_p->reset_system.DoSuspend;
  145. loongson_sysconf.vgabios_addr = boot_p->efi.smbios.vga_bios;
  146. pr_debug("Shutdown Addr: %llx, Restart Addr: %llx, VBIOS Addr: %llx\n",
  147. loongson_sysconf.poweroff_addr, loongson_sysconf.restart_addr,
  148. loongson_sysconf.vgabios_addr);
  149. memset(loongson_sysconf.ecname, 0, 32);
  150. if (esys->has_ec)
  151. memcpy(loongson_sysconf.ecname, esys->ec_name, 32);
  152. loongson_sysconf.workarounds |= esys->workarounds;
  153. loongson_sysconf.nr_uarts = esys->nr_uarts;
  154. if (esys->nr_uarts < 1 || esys->nr_uarts > MAX_UARTS)
  155. loongson_sysconf.nr_uarts = 1;
  156. memcpy(loongson_sysconf.uarts, esys->uarts,
  157. sizeof(struct uart_device) * loongson_sysconf.nr_uarts);
  158. loongson_sysconf.nr_sensors = esys->nr_sensors;
  159. if (loongson_sysconf.nr_sensors > MAX_SENSORS)
  160. loongson_sysconf.nr_sensors = 0;
  161. if (loongson_sysconf.nr_sensors)
  162. memcpy(loongson_sysconf.sensors, esys->sensors,
  163. sizeof(struct sensor_device) * loongson_sysconf.nr_sensors);
  164. #endif
  165. if (cpu_clock_freq == 0) {
  166. processor_id = (&current_cpu_data)->processor_id;
  167. switch (processor_id & PRID_REV_MASK) {
  168. case PRID_REV_LOONGSON2E:
  169. cpu_clock_freq = 533080000;
  170. break;
  171. case PRID_REV_LOONGSON2F:
  172. cpu_clock_freq = 797000000;
  173. break;
  174. case PRID_REV_LOONGSON3A_R1:
  175. case PRID_REV_LOONGSON3A_R2:
  176. cpu_clock_freq = 900000000;
  177. break;
  178. case PRID_REV_LOONGSON3B_R1:
  179. case PRID_REV_LOONGSON3B_R2:
  180. cpu_clock_freq = 1000000000;
  181. break;
  182. default:
  183. cpu_clock_freq = 100000000;
  184. break;
  185. }
  186. }
  187. pr_info("CpuClock = %u\n", cpu_clock_freq);
  188. }