Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Loongson{2ef, 32, 64} convert to generic fw cmdline

All of Loongson firmwares are passing boot cmdline/env
in the manner of YAMON/PMON. Thus we can remove duplicated
cmdline initialize code and convert to generic fw method.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Paul Burton <paulburton@kernel.org>
Cc: linux-mips@vger.kernel.org
Cc: chenhe@lemote.com

authored by

Jiaxun Yang and committed by
Paul Burton
75cac781 28e6b875

+28 -187
-1
arch/mips/include/asm/mach-loongson2ef/loongson.h
··· 25 25 26 26 /* loongson-specific command line, env and memory initialization */ 27 27 extern void __init prom_init_memory(void); 28 - extern void __init prom_init_cmdline(void); 29 28 extern void __init prom_init_machtype(void); 30 29 extern void __init prom_init_env(void); 31 30 #ifdef CONFIG_LOONGSON_UART_BASE
-20
arch/mips/include/asm/mach-loongson32/prom.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com> 4 - */ 5 - 6 - #ifndef __ASM_MACH_LOONGSON32_PROM_H 7 - #define __ASM_MACH_LOONGSON32_PROM_H 8 - 9 - #include <linux/io.h> 10 - #include <linux/init.h> 11 - #include <linux/irq.h> 12 - 13 - /* environment arguments from bootloader */ 14 - extern unsigned long memsize, highmemsize; 15 - 16 - /* loongson-specific command line, env and memory initialization */ 17 - extern char *prom_getenv(char *name); 18 - extern void __init prom_init_cmdline(void); 19 - 20 - #endif /* __ASM_MACH_LOONGSON32_PROM_H */
-1
arch/mips/include/asm/mach-loongson64/loongson.h
··· 24 24 25 25 /* loongson-specific command line, env and memory initialization */ 26 26 extern void __init prom_init_memory(void); 27 - extern void __init prom_init_cmdline(void); 28 27 extern void __init prom_init_env(void); 29 28 30 29 /* irq operation functions */
+1 -1
arch/mips/loongson2ef/common/Makefile
··· 3 3 # Makefile for loongson based machines. 4 4 # 5 5 6 - obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \ 6 + obj-y += setup.o init.o env.o time.o reset.o irq.o \ 7 7 bonito-irq.o mem.o machtype.o platform.o serial.o 8 8 obj-$(CONFIG_PCI) += pci.o 9 9
-44
arch/mips/loongson2ef/common/cmdline.c
··· 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 <asm/bootinfo.h> 17 - 18 - #include <loongson.h> 19 - 20 - void __init prom_init_cmdline(void) 21 - { 22 - int prom_argc; 23 - /* pmon passes arguments in 32bit pointers */ 24 - int *_prom_argv; 25 - int i; 26 - long l; 27 - 28 - /* firmware arguments are initialized in head.S */ 29 - prom_argc = fw_arg0; 30 - _prom_argv = (int *)fw_arg1; 31 - 32 - /* arg[0] is "g", the rest is boot parameters */ 33 - arcs_cmdline[0] = '\0'; 34 - for (i = 1; i < prom_argc; i++) { 35 - l = (long)_prom_argv[i]; 36 - if (strlen(arcs_cmdline) + strlen(((char *)l) + 1) 37 - >= sizeof(arcs_cmdline)) 38 - break; 39 - strcat(arcs_cmdline, ((char *)l)); 40 - strcat(arcs_cmdline, " "); 41 - } 42 - 43 - prom_init_machtype(); 44 - }
+4 -22
arch/mips/loongson2ef/common/env.c
··· 15 15 */ 16 16 #include <linux/export.h> 17 17 #include <asm/bootinfo.h> 18 + #include <asm/fw/fw.h> 18 19 #include <loongson.h> 19 20 20 21 u32 cpu_clock_freq; 21 22 EXPORT_SYMBOL(cpu_clock_freq); 22 23 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 24 void __init prom_init_env(void) 34 25 { 35 26 /* pmon passes arguments in 32bit pointers */ 36 27 unsigned int processor_id; 37 - int *_prom_envp; 38 - long l; 39 28 40 - /* firmware arguments are initialized in head.S */ 41 - _prom_envp = (int *)fw_arg2; 29 + cpu_clock_freq = fw_getenvl("cpuclock"); 30 + memsize = fw_getenvl("memsize"); 31 + highmemsize = fw_getenvl("highmemsize"); 42 32 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 33 if (memsize == 0) 52 34 memsize = 256; 53 35
+3 -1
arch/mips/loongson2ef/common/init.c
··· 9 9 #include <asm/traps.h> 10 10 #include <asm/smp-ops.h> 11 11 #include <asm/cacheflush.h> 12 + #include <asm/fw/fw.h> 12 13 13 14 #include <loongson.h> 14 15 ··· 33 32 ioremap(LOONGSON_ADDRWINCFG_BASE, LOONGSON_ADDRWINCFG_SIZE); 34 33 #endif 35 34 36 - prom_init_cmdline(); 35 + fw_init_cmdline(); 36 + prom_init_machtype(); 37 37 prom_init_env(); 38 38 39 39 /* init base address of io space */
+13 -46
arch/mips/loongson32/common/prom.c
··· 5 5 * Modified from arch/mips/pnx833x/common/prom.c. 6 6 */ 7 7 8 + #include <linux/io.h> 9 + #include <linux/init.h> 8 10 #include <linux/serial_reg.h> 9 11 #include <asm/bootinfo.h> 12 + #include <asm/fw/fw.h> 10 13 11 14 #include <loongson1.h> 12 - #include <prom.h> 13 15 14 - int prom_argc; 15 - char **prom_argv, **prom_envp; 16 - unsigned long memsize, highmemsize; 17 - 18 - char *prom_getenv(char *envname) 19 - { 20 - char **env = prom_envp; 21 - int i; 22 - 23 - i = strlen(envname); 24 - 25 - while (*env) { 26 - if (strncmp(envname, *env, i) == 0 && *(*env + i) == '=') 27 - return *env + i + 1; 28 - env++; 29 - } 30 - 31 - return 0; 32 - } 33 - 34 - static inline unsigned long env_or_default(char *env, unsigned long dfl) 35 - { 36 - char *str = prom_getenv(env); 37 - return str ? simple_strtol(str, 0, 0) : dfl; 38 - } 39 - 40 - void __init prom_init_cmdline(void) 41 - { 42 - char *c = &(arcs_cmdline[0]); 43 - int i; 44 - 45 - for (i = 1; i < prom_argc; i++) { 46 - strcpy(c, prom_argv[i]); 47 - c += strlen(prom_argv[i]); 48 - if (i < prom_argc - 1) 49 - *c++ = ' '; 50 - } 51 - *c = 0; 52 - } 16 + unsigned long memsize; 53 17 54 18 void __init prom_init(void) 55 19 { 56 20 void __iomem *uart_base; 57 - prom_argc = fw_arg0; 58 - prom_argv = (char **)fw_arg1; 59 - prom_envp = (char **)fw_arg2; 60 21 61 - prom_init_cmdline(); 22 + fw_init_cmdline(); 62 23 63 - memsize = env_or_default("memsize", DEFAULT_MEMSIZE); 64 - highmemsize = env_or_default("highmemsize", 0x0); 24 + memsize = fw_getenvl("memsize"); 25 + if(!memsize) 26 + memsize = DEFAULT_MEMSIZE; 65 27 66 28 if (strstr(arcs_cmdline, "console=ttyS3")) 67 29 uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f); ··· 38 76 39 77 void __init prom_free_prom_memory(void) 40 78 { 79 + } 80 + 81 + void __init plat_mem_setup(void) 82 + { 83 + add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM); 41 84 }
+4 -7
arch/mips/loongson32/common/setup.c
··· 3 3 * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com> 4 4 */ 5 5 6 + #include <linux/io.h> 7 + #include <linux/init.h> 8 + #include <linux/smp.h> 9 + #include <asm/cpu-info.h> 6 10 #include <asm/bootinfo.h> 7 - 8 - #include <prom.h> 9 - 10 - void __init plat_mem_setup(void) 11 - { 12 - add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM); 13 - } 14 11 15 12 const char *get_system_type(void) 16 13 {
+1 -1
arch/mips/loongson64/Makefile
··· 3 3 # Makefile for Loongson-3 family machines 4 4 # 5 5 obj-$(CONFIG_MACH_LOONGSON64) += irq.o cop2-ex.o platform.o acpi_init.o dma.o \ 6 - setup.o init.o cmdline.o env.o time.o reset.o \ 6 + setup.o init.o env.o time.o reset.o \ 7 7 8 8 obj-$(CONFIG_SMP) += smp.o 9 9 obj-$(CONFIG_NUMA) += numa.o
-42
arch/mips/loongson64/cmdline.c
··· 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 <asm/bootinfo.h> 17 - 18 - #include <loongson.h> 19 - 20 - void __init prom_init_cmdline(void) 21 - { 22 - int prom_argc; 23 - /* pmon passes arguments in 32bit pointers */ 24 - int *_prom_argv; 25 - int i; 26 - long l; 27 - 28 - /* firmware arguments are initialized in head.S */ 29 - prom_argc = fw_arg0; 30 - _prom_argv = (int *)fw_arg1; 31 - 32 - /* arg[0] is "g", the rest is boot parameters */ 33 - arcs_cmdline[0] = '\0'; 34 - for (i = 1; i < prom_argc; i++) { 35 - l = (long)_prom_argv[i]; 36 - if (strlen(arcs_cmdline) + strlen(((char *)l) + 1) 37 - >= sizeof(arcs_cmdline)) 38 - break; 39 - strcat(arcs_cmdline, ((char *)l)); 40 - strcat(arcs_cmdline, " "); 41 - } 42 - }
+2 -1
arch/mips/loongson64/init.c
··· 9 9 #include <asm/traps.h> 10 10 #include <asm/smp-ops.h> 11 11 #include <asm/cacheflush.h> 12 + #include <asm/fw/fw.h> 12 13 13 14 #include <loongson.h> 14 15 ··· 25 24 26 25 void __init prom_init(void) 27 26 { 28 - prom_init_cmdline(); 27 + fw_init_cmdline(); 29 28 prom_init_env(); 30 29 31 30 /* init base address of io space */