blob: dc592412f764e5f78e7c27a83729af061b9a0ed8 [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>
Wu Zhangjin5e983ff2009-07-02 23:23:03 +080024
Huacai Chen1a08f152014-03-21 18:44:02 +080025u32 cpu_clock_freq;
Wu Zhangjinf8ede0f2009-11-17 01:32:59 +080026EXPORT_SYMBOL(cpu_clock_freq);
Huacai Chen1a08f152014-03-21 18:44:02 +080027struct efi_memory_map_loongson *loongson_memmap;
28struct loongson_system_configuration loongson_sysconf;
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080029
Huacai Chen140e39c2014-06-26 11:41:27 +080030u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
31
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080032#define parse_even_earlier(res, option, p) \
33do { \
Ralf Baechlec87444a2011-03-29 12:32:55 +020034 unsigned int tmp __maybe_unused; \
35 \
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080036 if (strncmp(option, (char *)p, strlen(option)) == 0) \
Huacai Chen1a08f152014-03-21 18:44:02 +080037 tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080038} while (0)
39
40void __init prom_init_env(void)
41{
Wu Zhangjineb11df42010-01-04 17:16:48 +080042 /* pmon passes arguments in 32bit pointers */
Wu Zhangjineb11df42010-01-04 17:16:48 +080043 unsigned int processor_id;
Huacai Chen1a08f152014-03-21 18:44:02 +080044
45#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
46 int *_prom_envp;
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080047 long l;
48
49 /* firmware arguments are initialized in head.S */
50 _prom_envp = (int *)fw_arg2;
51
52 l = (long)*_prom_envp;
53 while (l != 0) {
Wu Zhangjinbd92aa02009-07-02 23:22:36 +080054 parse_even_earlier(cpu_clock_freq, "cpuclock", l);
55 parse_even_earlier(memsize, "memsize", l);
56 parse_even_earlier(highmemsize, "highmemsize", l);
57 _prom_envp++;
58 l = (long)*_prom_envp;
59 }
60 if (memsize == 0)
61 memsize = 256;
Huacai Chen1a08f152014-03-21 18:44:02 +080062 pr_info("memsize=%u, highmemsize=%u\n", memsize, highmemsize);
63#else
64 struct boot_params *boot_p;
65 struct loongson_params *loongson_p;
66 struct efi_cpuinfo_loongson *ecpu;
67 struct irq_source_routing_table *eirq_source;
68
69 /* firmware arguments are initialized in head.S */
70 boot_p = (struct boot_params *)fw_arg2;
71 loongson_p = &(boot_p->efi.smbios.lp);
72
73 ecpu = (struct efi_cpuinfo_loongson *)
74 ((u64)loongson_p + loongson_p->cpu_offset);
75 eirq_source = (struct irq_source_routing_table *)
76 ((u64)loongson_p + loongson_p->irq_offset);
77 loongson_memmap = (struct efi_memory_map_loongson *)
78 ((u64)loongson_p + loongson_p->memory_offset);
79
80 cpu_clock_freq = ecpu->cpu_clock_freq;
81 loongson_sysconf.cputype = ecpu->cputype;
Huacai Chen140e39c2014-06-26 11:41:27 +080082 if (ecpu->cputype == Loongson_3A) {
83 loongson_chipcfg[0] = 0x900000001fe00180;
84 loongson_chipcfg[1] = 0x900010001fe00180;
85 loongson_chipcfg[2] = 0x900020001fe00180;
86 loongson_chipcfg[3] = 0x900030001fe00180;
87 } else {
88 loongson_chipcfg[0] = 0x900000001fe00180;
89 }
90
Huacai Chen1a08f152014-03-21 18:44:02 +080091 loongson_sysconf.nr_cpus = ecpu->nr_cpus;
92 if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0)
93 loongson_sysconf.nr_cpus = NR_CPUS;
94
95 loongson_sysconf.pci_mem_start_addr = eirq_source->pci_mem_start_addr;
96 loongson_sysconf.pci_mem_end_addr = eirq_source->pci_mem_end_addr;
97 loongson_sysconf.pci_io_base = eirq_source->pci_io_start_addr;
98 loongson_sysconf.dma_mask_bits = eirq_source->dma_mask_bits;
99 if (loongson_sysconf.dma_mask_bits < 32 ||
100 loongson_sysconf.dma_mask_bits > 64)
101 loongson_sysconf.dma_mask_bits = 32;
102
103 loongson_sysconf.restart_addr = boot_p->reset_system.ResetWarm;
104 loongson_sysconf.poweroff_addr = boot_p->reset_system.Shutdown;
105 loongson_sysconf.suspend_addr = boot_p->reset_system.DoSuspend;
106
107 loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
108 loongson_sysconf.vgabios_addr = boot_p->efi.smbios.vga_bios;
109 pr_debug("Shutdown Addr: %llx, Restart Addr: %llx, VBIOS Addr: %llx\n",
110 loongson_sysconf.poweroff_addr, loongson_sysconf.restart_addr,
111 loongson_sysconf.vgabios_addr);
112#endif
Wu Zhangjineb11df42010-01-04 17:16:48 +0800113 if (cpu_clock_freq == 0) {
114 processor_id = (&current_cpu_data)->processor_id;
115 switch (processor_id & PRID_REV_MASK) {
116 case PRID_REV_LOONGSON2E:
117 cpu_clock_freq = 533080000;
118 break;
119 case PRID_REV_LOONGSON2F:
120 cpu_clock_freq = 797000000;
121 break;
Huacai Chen1a08f152014-03-21 18:44:02 +0800122 case PRID_REV_LOONGSON3A:
123 cpu_clock_freq = 900000000;
124 break;
Wu Zhangjineb11df42010-01-04 17:16:48 +0800125 default:
126 cpu_clock_freq = 100000000;
127 break;
128 }
129 }
Huacai Chen1a08f152014-03-21 18:44:02 +0800130 pr_info("CpuClock = %u\n", cpu_clock_freq);
Wu Zhangjinbd92aa02009-07-02 23:22:36 +0800131}