1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Based on Ocelot Linux port, which is 4 * Copyright 2001 MontaVista Software Inc. 5 * Author: jsun@mvista.com or jsun@junsun.net 6 * 7 * Copyright 2003 ICT CAS 8 * Author: Michael Guo <guoyi@ict.ac.cn> 9 * 10 * Copyright (C) 2007 Lemote Inc. & Institute of Computing Technology 11 * Author: Fuxin Zhang, zhangfx@lemote.com 12 * 13 * Copyright (C) 2009 Lemote Inc. 14 * Author: Wu Zhangjin, wuzhangjin@gmail.com 15 */ 16 #include <linux/export.h> 17 #include <asm/bootinfo.h> 18 #include <loongson.h> 19 20 u32 cpu_clock_freq; 21 EXPORT_SYMBOL(cpu_clock_freq); 22 23 unsigned long long smp_group[4]; 24 25 #define parse_even_earlier(res, option, p) \ 26 do { \ 27 unsigned int tmp __maybe_unused; \ 28 \ 29 if (strncmp(option, (char *)p, strlen(option)) == 0) \ 30 tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \ 31 } while (0) 32 33 void __init prom_init_env(void) 34 { 35 /* pmon passes arguments in 32bit pointers */ 36 unsigned int processor_id; 37 int *_prom_envp; 38 long l; 39 40 /* firmware arguments are initialized in head.S */ 41 _prom_envp = (int *)fw_arg2; 42 43 l = (long)*_prom_envp; 44 while (l != 0) { 45 parse_even_earlier(cpu_clock_freq, "cpuclock", l); 46 parse_even_earlier(memsize, "memsize", l); 47 parse_even_earlier(highmemsize, "highmemsize", l); 48 _prom_envp++; 49 l = (long)*_prom_envp; 50 } 51 if (memsize == 0) 52 memsize = 256; 53 54 pr_info("memsize=%u, highmemsize=%u\n", memsize, highmemsize); 55 56 if (cpu_clock_freq == 0) { 57 processor_id = (¤t_cpu_data)->processor_id; 58 switch (processor_id & PRID_REV_MASK) { 59 case PRID_REV_LOONGSON2E: 60 cpu_clock_freq = 533080000; 61 break; 62 case PRID_REV_LOONGSON2F: 63 cpu_clock_freq = 797000000; 64 break; 65 default: 66 cpu_clock_freq = 100000000; 67 break; 68 } 69 } 70 pr_info("CpuClock = %u\n", cpu_clock_freq); 71 } 72