Linux 3.15-rc1
[linux/fpc-iii.git] / arch / mips / loongson / common / env.c
blob0c543eae49bfd059b3b6900062deede511c80bbc
1 /*
2 * Based on Ocelot Linux port, which is
3 * Copyright 2001 MontaVista Software Inc.
4 * Author: jsun@mvista.com or jsun@junsun.net
6 * Copyright 2003 ICT CAS
7 * Author: Michael Guo <guoyi@ict.ac.cn>
9 * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
10 * Author: Fuxin Zhang, zhangfx@lemote.com
12 * Copyright (C) 2009 Lemote Inc.
13 * Author: Wu Zhangjin, wuzhangjin@gmail.com
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.
20 #include <linux/module.h>
21 #include <asm/bootinfo.h>
22 #include <loongson.h>
23 #include <boot_param.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;
30 #define parse_even_earlier(res, option, p) \
31 do { \
32 unsigned int tmp __maybe_unused; \
34 if (strncmp(option, (char *)p, strlen(option)) == 0) \
35 tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \
36 } while (0)
38 void __init prom_init_env(void)
40 /* pmon passes arguments in 32bit pointers */
41 unsigned int processor_id;
43 #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
44 int *_prom_envp;
45 long l;
47 /* firmware arguments are initialized in head.S */
48 _prom_envp = (int *)fw_arg2;
50 l = (long)*_prom_envp;
51 while (l != 0) {
52 parse_even_earlier(cpu_clock_freq, "cpuclock", l);
53 parse_even_earlier(memsize, "memsize", l);
54 parse_even_earlier(highmemsize, "highmemsize", l);
55 _prom_envp++;
56 l = (long)*_prom_envp;
58 if (memsize == 0)
59 memsize = 256;
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 efi_cpuinfo_loongson *ecpu;
65 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);
71 ecpu = (struct efi_cpuinfo_loongson *)
72 ((u64)loongson_p + loongson_p->cpu_offset);
73 eirq_source = (struct irq_source_routing_table *)
74 ((u64)loongson_p + loongson_p->irq_offset);
75 loongson_memmap = (struct efi_memory_map_loongson *)
76 ((u64)loongson_p + loongson_p->memory_offset);
78 cpu_clock_freq = ecpu->cpu_clock_freq;
79 loongson_sysconf.cputype = ecpu->cputype;
80 loongson_sysconf.nr_cpus = ecpu->nr_cpus;
81 if (ecpu->nr_cpus > NR_CPUS || ecpu->nr_cpus == 0)
82 loongson_sysconf.nr_cpus = NR_CPUS;
84 loongson_sysconf.pci_mem_start_addr = eirq_source->pci_mem_start_addr;
85 loongson_sysconf.pci_mem_end_addr = eirq_source->pci_mem_end_addr;
86 loongson_sysconf.pci_io_base = eirq_source->pci_io_start_addr;
87 loongson_sysconf.dma_mask_bits = eirq_source->dma_mask_bits;
88 if (loongson_sysconf.dma_mask_bits < 32 ||
89 loongson_sysconf.dma_mask_bits > 64)
90 loongson_sysconf.dma_mask_bits = 32;
92 loongson_sysconf.restart_addr = boot_p->reset_system.ResetWarm;
93 loongson_sysconf.poweroff_addr = boot_p->reset_system.Shutdown;
94 loongson_sysconf.suspend_addr = boot_p->reset_system.DoSuspend;
96 loongson_sysconf.ht_control_base = 0x90000EFDFB000000;
97 loongson_sysconf.vgabios_addr = boot_p->efi.smbios.vga_bios;
98 pr_debug("Shutdown Addr: %llx, Restart Addr: %llx, VBIOS Addr: %llx\n",
99 loongson_sysconf.poweroff_addr, loongson_sysconf.restart_addr,
100 loongson_sysconf.vgabios_addr);
101 #endif
102 if (cpu_clock_freq == 0) {
103 processor_id = (&current_cpu_data)->processor_id;
104 switch (processor_id & PRID_REV_MASK) {
105 case PRID_REV_LOONGSON2E:
106 cpu_clock_freq = 533080000;
107 break;
108 case PRID_REV_LOONGSON2F:
109 cpu_clock_freq = 797000000;
110 break;
111 case PRID_REV_LOONGSON3A:
112 cpu_clock_freq = 900000000;
113 break;
114 default:
115 cpu_clock_freq = 100000000;
116 break;
119 pr_info("CpuClock = %u\n", cpu_clock_freq);