blob: 22f04ca2ff3e58cd9ddddfa1ded6d84e5147efa0 [file] [log] [blame]
Wu Zhangjinbd92aa02009-07-02 23:22:36 +08001/*
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 *
Wu Zhangjinf7a904d2010-01-04 17:16:51 +080012 * Copyright (C) 2009 Lemote Inc.
13 * Author: Wu Zhangjin, wuzhangjin@gmail.com
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080014 *
Ralf Baechle70342282013-01-22 12:59:30 +010015 * 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
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080017 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
19 */
Wu Zhangjinf8ede0f2009-11-17 01:32:59 +080020#include <linux/module.h>
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080021#include <asm/bootinfo.h>
Wu Zhangjin5e983ff2009-07-02 23:23:03 +080022#include <loongson.h>
Huacai Chen1a08f152014-03-21 18:44:02 +080023#include <boot_param.h>
Huacai Chen3adeb252014-11-04 14:13:27 +080024#include <workarounds.h>
Wu Zhangjin5e983ff2009-07-02 23:23:03 +080025
Huacai Chen1a08f152014-03-21 18:44:02 +080026u32 cpu_clock_freq;
Wu Zhangjinf8ede0f2009-11-17 01:32:59 +080027EXPORT_SYMBOL(cpu_clock_freq);
Huacai Chen1a08f152014-03-21 18:44:02 +080028struct efi_memory_map_loongson *loongson_memmap;
29struct loongson_system_configuration loongson_sysconf;
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080030
Huacai Chen140e39c2014-06-26 11:41:27 +080031u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
Huacai Chen64f09aa2015-03-29 10:54:09 +080032u64 loongson_chiptemp[MAX_PACKAGES];
Huacai Chene7841be2014-06-26 11:41:30 +080033u64 loongson_freqctrl[MAX_PACKAGES];
34
35unsigned long long smp_group[4];
Huacai Chen140e39c2014-06-26 11:41:27 +080036
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080037#define parse_even_earlier(res, option, p) \
38do { \
Ralf Baechlec87444a2011-03-29 12:32:55 +020039 unsigned int tmp __maybe_unused; \
40 \
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080041 if (strncmp(option, (char *)p, strlen(option)) == 0) \
Huacai Chen1a08f152014-03-21 18:44:02 +080042 tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080043} while (0)
44
45void __init prom_init_env(void)
46{
Wu Zhangjineb11df42010-01-04 17:16:48 +080047 /* pmon passes arguments in 32bit pointers */
Wu Zhangjineb11df42010-01-04 17:16:48 +080048 unsigned int processor_id;
Huacai Chen1a08f152014-03-21 18:44:02 +080049
50#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
51 int *_prom_envp;
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080052 long l;
53
54 /* firmware arguments are initialized in head.S */
55 _prom_envp = (int *)fw_arg2;
56
57 l = (long)*_prom_envp;
58 while (l != 0) {
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080059 parse_even_earlier(cpu_clock_freq, "cpuclock", l);
60 parse_even_earlier(memsize, "memsize", l);
61 parse_even_earlier(highmemsize, "highmemsize", l);
62 _prom_envp++;
63 l = (long)*_prom_envp;
64 }
65 if (memsize == 0)
66 memsize = 256;
Huacai Chen1a08f152014-03-21 18:44:02 +080067 pr_info("memsize=%u, highmemsize=%u\n", memsize, highmemsize);
68#else
69 struct boot_params *boot_p;
70 struct loongson_params *loongson_p;
Huacai Chen3adeb252014-11-04 14:13:27 +080071 struct system_loongson *esys;
Huacai Chen1a08f152014-03-21 18:44:02 +080072 struct efi_cpuinfo_loongson *ecpu;
73 struct irq_source_routing_table *eirq_source;
74
75 /* firmware arguments are initialized in head.S */
76 boot_p = (struct boot_params *)fw_arg2;
77 loongson_p = &(boot_p->efi.smbios.lp);
78
Huacai Chen3adeb252014-11-04 14:13:27 +080079 esys = (struct system_loongson *)
80 ((u64)loongson_p + loongson_p->system_offset);
Huacai Chen1a08f152014-03-21 18:44:02 +080081 ecpu = (struct efi_cpuinfo_loongson *)
82 ((u64)loongson_p + loongson_p->cpu_offset);
83 eirq_source = (struct irq_source_routing_table *)
84 ((u64)loongson_p + loongson_p->irq_offset);
85 loongson_memmap = (struct efi_memory_map_loongson *)
86 ((u64)loongson_p + loongson_p->memory_offset);
87
88 cpu_clock_freq = ecpu->cpu_clock_freq;
89 loongson_sysconf.cputype = ecpu->cputype;
Huacai Chen140e39c2014-06-26 11:41:27 +080090 if (ecpu->cputype == Loongson_3A) {
Huacai Chenc4617312014-06-26 11:41:28 +080091 loongson_sysconf.cores_per_node = 4;
92 loongson_sysconf.cores_per_package = 4;
Huacai Chene7841be2014-06-26 11:41:30 +080093 smp_group[0] = 0x900000003ff01000;
94 smp_group[1] = 0x900010003ff01000;
95 smp_group[2] = 0x900020003ff01000;
96 smp_group[3] = 0x900030003ff01000;
Huacai Chen140e39c2014-06-26 11:41:27 +080097 loongson_chipcfg[0] = 0x900000001fe00180;
98 loongson_chipcfg[1] = 0x900010001fe00180;
99 loongson_chipcfg[2] = 0x900020001fe00180;
100 loongson_chipcfg[3] = 0x900030001fe00180;
Huacai Chen64f09aa2015-03-29 10:54:09 +0800101 loongson_chiptemp[0] = 0x900000001fe0019c;
102 loongson_chiptemp[1] = 0x900010001fe0019c;
103 loongson_chiptemp[2] = 0x900020001fe0019c;
104 loongson_chiptemp[3] = 0x900030001fe0019c;
Huacai Chene7841be2014-06-26 11:41:30 +0800105 loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
Huacai Chen3adeb252014-11-04 14:13:27 +0800106 loongson_sysconf.workarounds = WORKAROUND_CPUFREQ;
Huacai Chene7841be2014-06-26 11:41:30 +0800107 } else if (ecpu->cputype == Loongson_3B) {
108 loongson_sysconf.cores_per_node = 4; /* One chip has 2 nodes */
109 loongson_sysconf.cores_per_package = 8;
110 smp_group[0] = 0x900000003ff01000;
111 smp_group[1] = 0x900010003ff05000;
112 smp_group[2] = 0x900020003ff09000;
113 smp_group[3] = 0x900030003ff0d000;
114 loongson_chipcfg[0] = 0x900000001fe00180;
115 loongson_chipcfg[1] = 0x900020001fe00180;
116 loongson_chipcfg[2] = 0x900040001fe00180;
117 loongson_chipcfg[3] = 0x900060001fe00180;
Huacai Chen64f09aa2015-03-29 10:54:09 +0800118 loongson_chiptemp[0] = 0x900000001fe0019c;
119 loongson_chiptemp[1] = 0x900020001fe0019c;
120 loongson_chiptemp[2] = 0x900040001fe0019c;
121 loongson_chiptemp[3] = 0x900060001fe0019c;
Huacai Chene7841be2014-06-26 11:41:30 +0800122 loongson_freqctrl[0] = 0x900000001fe001d0;
123 loongson_freqctrl[1] = 0x900020001fe001d0;
124 loongson_freqctrl[2] = 0x900040001fe001d0;
125 loongson_freqctrl[3] = 0x900060001fe001d0;
126 loongson_sysconf.ht_control_base = 0x90001EFDFB000000;
Huacai Chen3adeb252014-11-04 14:13:27 +0800127 loongson_sysconf.workarounds = WORKAROUND_CPUHOTPLUG;
Huacai Chen140e39c2014-06-26 11:41:27 +0800128 } else {
Huacai Chenc4617312014-06-26 11:41:28 +0800129 loongson_sysconf.cores_per_node = 1;
130 loongson_sysconf.cores_per_package = 1;
Huacai Chen140e39c2014-06-26 11:41:27 +0800131 loongson_chipcfg[0] = 0x900000001fe00180;
132 }
133
Huacai Chen1a08f152014-03-21 18:44:02 +0800134 loongson_sysconf.nr_cpus = ecpu->nr_cpus;
Huacai Chenec0f8d32014-11-04 14:13:26 +0800135 loongson_sysconf.boot_cpu_id = ecpu->cpu_startup_core_id;
136 loongson_sysconf.reserved_cpus_mask = ecpu->reserved_cores_mask;
Huacai Chen1a08f152014-03-21 18:44:02 +0800137 if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0)
138 loongson_sysconf.nr_cpus = NR_CPUS;
Huacai Chenc4617312014-06-26 11:41:28 +0800139 loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus +
140 loongson_sysconf.cores_per_node - 1) /
141 loongson_sysconf.cores_per_node;
Huacai Chen1a08f152014-03-21 18:44:02 +0800142
143 loongson_sysconf.pci_mem_start_addr = eirq_source->pci_mem_start_addr;
144 loongson_sysconf.pci_mem_end_addr = eirq_source->pci_mem_end_addr;
145 loongson_sysconf.pci_io_base = eirq_source->pci_io_start_addr;
146 loongson_sysconf.dma_mask_bits = eirq_source->dma_mask_bits;
147 if (loongson_sysconf.dma_mask_bits < 32 ||
148 loongson_sysconf.dma_mask_bits > 64)
149 loongson_sysconf.dma_mask_bits = 32;
150
151 loongson_sysconf.restart_addr = boot_p->reset_system.ResetWarm;
152 loongson_sysconf.poweroff_addr = boot_p->reset_system.Shutdown;
153 loongson_sysconf.suspend_addr = boot_p->reset_system.DoSuspend;
154
Huacai Chen1a08f152014-03-21 18:44:02 +0800155 loongson_sysconf.vgabios_addr = boot_p->efi.smbios.vga_bios;
156 pr_debug("Shutdown Addr: %llx, Restart Addr: %llx, VBIOS Addr: %llx\n",
157 loongson_sysconf.poweroff_addr, loongson_sysconf.restart_addr,
158 loongson_sysconf.vgabios_addr);
Huacai Chen3adeb252014-11-04 14:13:27 +0800159
160 memset(loongson_sysconf.ecname, 0, 32);
161 if (esys->has_ec)
162 memcpy(loongson_sysconf.ecname, esys->ec_name, 32);
163 loongson_sysconf.workarounds |= esys->workarounds;
164
165 loongson_sysconf.nr_uarts = esys->nr_uarts;
166 if (esys->nr_uarts < 1 || esys->nr_uarts > MAX_UARTS)
167 loongson_sysconf.nr_uarts = 1;
168 memcpy(loongson_sysconf.uarts, esys->uarts,
169 sizeof(struct uart_device) * loongson_sysconf.nr_uarts);
170
171 loongson_sysconf.nr_sensors = esys->nr_sensors;
172 if (loongson_sysconf.nr_sensors > MAX_SENSORS)
173 loongson_sysconf.nr_sensors = 0;
174 if (loongson_sysconf.nr_sensors)
175 memcpy(loongson_sysconf.sensors, esys->sensors,
176 sizeof(struct sensor_device) * loongson_sysconf.nr_sensors);
Huacai Chen1a08f152014-03-21 18:44:02 +0800177#endif
Wu Zhangjineb11df42010-01-04 17:16:48 +0800178 if (cpu_clock_freq == 0) {
179 processor_id = (&current_cpu_data)->processor_id;
180 switch (processor_id & PRID_REV_MASK) {
181 case PRID_REV_LOONGSON2E:
182 cpu_clock_freq = 533080000;
183 break;
184 case PRID_REV_LOONGSON2F:
185 cpu_clock_freq = 797000000;
186 break;
Huacai Chen1a08f152014-03-21 18:44:02 +0800187 case PRID_REV_LOONGSON3A:
188 cpu_clock_freq = 900000000;
189 break;
Huacai Chene7841be2014-06-26 11:41:30 +0800190 case PRID_REV_LOONGSON3B_R1:
191 case PRID_REV_LOONGSON3B_R2:
192 cpu_clock_freq = 1000000000;
193 break;
Wu Zhangjineb11df42010-01-04 17:16:48 +0800194 default:
195 cpu_clock_freq = 100000000;
196 break;
197 }
198 }
Huacai Chen1a08f152014-03-21 18:44:02 +0800199 pr_info("CpuClock = %u\n", cpu_clock_freq);
Wu Zhangjinbd92aa02009-07-02 23:22:36 +0800200}