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
This commit is contained in:
Jiaxun Yang 2019-11-07 12:01:15 +08:00 committed by Paul Burton
parent 28e6b875fd
commit 75cac781dc
No known key found for this signature in database
GPG Key ID: 3EA79FACB57500DD
12 changed files with 28 additions and 187 deletions

View File

@ -25,7 +25,6 @@ extern const struct plat_smp_ops loongson3_smp_ops;
/* loongson-specific command line, env and memory initialization */ /* loongson-specific command line, env and memory initialization */
extern void __init prom_init_memory(void); extern void __init prom_init_memory(void);
extern void __init prom_init_cmdline(void);
extern void __init prom_init_machtype(void); extern void __init prom_init_machtype(void);
extern void __init prom_init_env(void); extern void __init prom_init_env(void);
#ifdef CONFIG_LOONGSON_UART_BASE #ifdef CONFIG_LOONGSON_UART_BASE

View File

@ -1,20 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
*/
#ifndef __ASM_MACH_LOONGSON32_PROM_H
#define __ASM_MACH_LOONGSON32_PROM_H
#include <linux/io.h>
#include <linux/init.h>
#include <linux/irq.h>
/* environment arguments from bootloader */
extern unsigned long memsize, highmemsize;
/* loongson-specific command line, env and memory initialization */
extern char *prom_getenv(char *name);
extern void __init prom_init_cmdline(void);
#endif /* __ASM_MACH_LOONGSON32_PROM_H */

View File

@ -24,7 +24,6 @@ extern const struct plat_smp_ops loongson3_smp_ops;
/* loongson-specific command line, env and memory initialization */ /* loongson-specific command line, env and memory initialization */
extern void __init prom_init_memory(void); extern void __init prom_init_memory(void);
extern void __init prom_init_cmdline(void);
extern void __init prom_init_env(void); extern void __init prom_init_env(void);
/* irq operation functions */ /* irq operation functions */

View File

@ -3,7 +3,7 @@
# Makefile for loongson based machines. # Makefile for loongson based machines.
# #
obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \ obj-y += setup.o init.o env.o time.o reset.o irq.o \
bonito-irq.o mem.o machtype.o platform.o serial.o bonito-irq.o mem.o machtype.o platform.o serial.o
obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PCI) += pci.o

View File

@ -1,44 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Based on Ocelot Linux port, which is
* Copyright 2001 MontaVista Software Inc.
* Author: jsun@mvista.com or jsun@junsun.net
*
* Copyright 2003 ICT CAS
* Author: Michael Guo <guoyi@ict.ac.cn>
*
* Copyright (C) 2007 Lemote Inc. & Institute of Computing Technology
* Author: Fuxin Zhang, zhangfx@lemote.com
*
* Copyright (C) 2009 Lemote Inc.
* Author: Wu Zhangjin, wuzhangjin@gmail.com
*/
#include <asm/bootinfo.h>
#include <loongson.h>
void __init prom_init_cmdline(void)
{
int prom_argc;
/* pmon passes arguments in 32bit pointers */
int *_prom_argv;
int i;
long l;
/* firmware arguments are initialized in head.S */
prom_argc = fw_arg0;
_prom_argv = (int *)fw_arg1;
/* arg[0] is "g", the rest is boot parameters */
arcs_cmdline[0] = '\0';
for (i = 1; i < prom_argc; i++) {
l = (long)_prom_argv[i];
if (strlen(arcs_cmdline) + strlen(((char *)l) + 1)
>= sizeof(arcs_cmdline))
break;
strcat(arcs_cmdline, ((char *)l));
strcat(arcs_cmdline, " ");
}
prom_init_machtype();
}

View File

@ -15,39 +15,21 @@
*/ */
#include <linux/export.h> #include <linux/export.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
#include <asm/fw/fw.h>
#include <loongson.h> #include <loongson.h>
u32 cpu_clock_freq; u32 cpu_clock_freq;
EXPORT_SYMBOL(cpu_clock_freq); EXPORT_SYMBOL(cpu_clock_freq);
unsigned long long smp_group[4];
#define parse_even_earlier(res, option, p) \
do { \
unsigned int tmp __maybe_unused; \
\
if (strncmp(option, (char *)p, strlen(option)) == 0) \
tmp = kstrtou32((char *)p + strlen(option"="), 10, &res); \
} while (0)
void __init prom_init_env(void) void __init prom_init_env(void)
{ {
/* pmon passes arguments in 32bit pointers */ /* pmon passes arguments in 32bit pointers */
unsigned int processor_id; unsigned int processor_id;
int *_prom_envp;
long l;
/* firmware arguments are initialized in head.S */ cpu_clock_freq = fw_getenvl("cpuclock");
_prom_envp = (int *)fw_arg2; memsize = fw_getenvl("memsize");
highmemsize = fw_getenvl("highmemsize");
l = (long)*_prom_envp;
while (l != 0) {
parse_even_earlier(cpu_clock_freq, "cpuclock", l);
parse_even_earlier(memsize, "memsize", l);
parse_even_earlier(highmemsize, "highmemsize", l);
_prom_envp++;
l = (long)*_prom_envp;
}
if (memsize == 0) if (memsize == 0)
memsize = 256; memsize = 256;

View File

@ -9,6 +9,7 @@
#include <asm/traps.h> #include <asm/traps.h>
#include <asm/smp-ops.h> #include <asm/smp-ops.h>
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/fw/fw.h>
#include <loongson.h> #include <loongson.h>
@ -32,7 +33,8 @@ void __init prom_init(void)
ioremap(LOONGSON_ADDRWINCFG_BASE, LOONGSON_ADDRWINCFG_SIZE); ioremap(LOONGSON_ADDRWINCFG_BASE, LOONGSON_ADDRWINCFG_SIZE);
#endif #endif
prom_init_cmdline(); fw_init_cmdline();
prom_init_machtype();
prom_init_env(); prom_init_env();
/* init base address of io space */ /* init base address of io space */

View File

@ -5,63 +5,25 @@
* Modified from arch/mips/pnx833x/common/prom.c. * Modified from arch/mips/pnx833x/common/prom.c.
*/ */
#include <linux/io.h>
#include <linux/init.h>
#include <linux/serial_reg.h> #include <linux/serial_reg.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
#include <asm/fw/fw.h>
#include <loongson1.h> #include <loongson1.h>
#include <prom.h>
int prom_argc; unsigned long memsize;
char **prom_argv, **prom_envp;
unsigned long memsize, highmemsize;
char *prom_getenv(char *envname)
{
char **env = prom_envp;
int i;
i = strlen(envname);
while (*env) {
if (strncmp(envname, *env, i) == 0 && *(*env + i) == '=')
return *env + i + 1;
env++;
}
return 0;
}
static inline unsigned long env_or_default(char *env, unsigned long dfl)
{
char *str = prom_getenv(env);
return str ? simple_strtol(str, 0, 0) : dfl;
}
void __init prom_init_cmdline(void)
{
char *c = &(arcs_cmdline[0]);
int i;
for (i = 1; i < prom_argc; i++) {
strcpy(c, prom_argv[i]);
c += strlen(prom_argv[i]);
if (i < prom_argc - 1)
*c++ = ' ';
}
*c = 0;
}
void __init prom_init(void) void __init prom_init(void)
{ {
void __iomem *uart_base; void __iomem *uart_base;
prom_argc = fw_arg0;
prom_argv = (char **)fw_arg1;
prom_envp = (char **)fw_arg2;
prom_init_cmdline(); fw_init_cmdline();
memsize = env_or_default("memsize", DEFAULT_MEMSIZE); memsize = fw_getenvl("memsize");
highmemsize = env_or_default("highmemsize", 0x0); if(!memsize)
memsize = DEFAULT_MEMSIZE;
if (strstr(arcs_cmdline, "console=ttyS3")) if (strstr(arcs_cmdline, "console=ttyS3"))
uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f); uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f);
@ -77,3 +39,8 @@ void __init prom_init(void)
void __init prom_free_prom_memory(void) void __init prom_free_prom_memory(void)
{ {
} }
void __init plat_mem_setup(void)
{
add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
}

View File

@ -3,15 +3,12 @@
* Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com> * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
*/ */
#include <linux/io.h>
#include <linux/init.h>
#include <linux/smp.h>
#include <asm/cpu-info.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
#include <prom.h>
void __init plat_mem_setup(void)
{
add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
}
const char *get_system_type(void) const char *get_system_type(void)
{ {
unsigned int processor_id = (&current_cpu_data)->processor_id; unsigned int processor_id = (&current_cpu_data)->processor_id;

View File

@ -3,7 +3,7 @@
# Makefile for Loongson-3 family machines # Makefile for Loongson-3 family machines
# #
obj-$(CONFIG_MACH_LOONGSON64) += irq.o cop2-ex.o platform.o acpi_init.o dma.o \ obj-$(CONFIG_MACH_LOONGSON64) += irq.o cop2-ex.o platform.o acpi_init.o dma.o \
setup.o init.o cmdline.o env.o time.o reset.o \ setup.o init.o env.o time.o reset.o \
obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SMP) += smp.o
obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_NUMA) += numa.o

View File

@ -1,42 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Based on Ocelot Linux port, which is
* Copyright 2001 MontaVista Software Inc.
* Author: jsun@mvista.com or jsun@junsun.net
*
* Copyright 2003 ICT CAS
* Author: Michael Guo <guoyi@ict.ac.cn>
*
* Copyright (C) 2007 Lemote Inc. & Institute of Computing Technology
* Author: Fuxin Zhang, zhangfx@lemote.com
*
* Copyright (C) 2009 Lemote Inc.
* Author: Wu Zhangjin, wuzhangjin@gmail.com
*/
#include <asm/bootinfo.h>
#include <loongson.h>
void __init prom_init_cmdline(void)
{
int prom_argc;
/* pmon passes arguments in 32bit pointers */
int *_prom_argv;
int i;
long l;
/* firmware arguments are initialized in head.S */
prom_argc = fw_arg0;
_prom_argv = (int *)fw_arg1;
/* arg[0] is "g", the rest is boot parameters */
arcs_cmdline[0] = '\0';
for (i = 1; i < prom_argc; i++) {
l = (long)_prom_argv[i];
if (strlen(arcs_cmdline) + strlen(((char *)l) + 1)
>= sizeof(arcs_cmdline))
break;
strcat(arcs_cmdline, ((char *)l));
strcat(arcs_cmdline, " ");
}
}

View File

@ -9,6 +9,7 @@
#include <asm/traps.h> #include <asm/traps.h>
#include <asm/smp-ops.h> #include <asm/smp-ops.h>
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/fw/fw.h>
#include <loongson.h> #include <loongson.h>
@ -24,7 +25,7 @@ static void __init mips_nmi_setup(void)
void __init prom_init(void) void __init prom_init(void)
{ {
prom_init_cmdline(); fw_init_cmdline();
prom_init_env(); prom_init_env();
/* init base address of io space */ /* init base address of io space */