prom.c (75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37) prom.c (75cac781dca43e735fbb4166d994263a14f0823e)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
4 *
5 * Modified from arch/mips/pnx833x/common/prom.c.
6 */
7
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
4 *
5 * Modified from arch/mips/pnx833x/common/prom.c.
6 */
7
8#include <linux/io.h>
9#include <linux/init.h>
8#include <linux/serial_reg.h>
9#include <asm/bootinfo.h>
10#include <linux/serial_reg.h>
11#include <asm/bootinfo.h>
12#include <asm/fw/fw.h>
10
11#include <loongson1.h>
13
14#include <loongson1.h>
12#include <prom.h>
13
15
14int prom_argc;
15char **prom_argv, **prom_envp;
16unsigned long memsize, highmemsize;
16unsigned long memsize;
17
17
18char *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
34static 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
40void __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}
53
54void __init prom_init(void)
55{
56 void __iomem *uart_base;
18void __init prom_init(void)
19{
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
66 if (strstr(arcs_cmdline, "console=ttyS3"))
67 uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f);
68 else if (strstr(arcs_cmdline, "console=ttyS2"))
69 uart_base = ioremap_nocache(LS1X_UART2_BASE, 0x0f);
70 else if (strstr(arcs_cmdline, "console=ttyS1"))
71 uart_base = ioremap_nocache(LS1X_UART1_BASE, 0x0f);
72 else
73 uart_base = ioremap_nocache(LS1X_UART0_BASE, 0x0f);
74 setup_8250_early_printk_port((unsigned long)uart_base, 0, 0);
75}
76
77void __init prom_free_prom_memory(void)
78{
79}
27
28 if (strstr(arcs_cmdline, "console=ttyS3"))
29 uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f);
30 else if (strstr(arcs_cmdline, "console=ttyS2"))
31 uart_base = ioremap_nocache(LS1X_UART2_BASE, 0x0f);
32 else if (strstr(arcs_cmdline, "console=ttyS1"))
33 uart_base = ioremap_nocache(LS1X_UART1_BASE, 0x0f);
34 else
35 uart_base = ioremap_nocache(LS1X_UART0_BASE, 0x0f);
36 setup_8250_early_printk_port((unsigned long)uart_base, 0, 0);
37}
38
39void __init prom_free_prom_memory(void)
40{
41}
42
43void __init plat_mem_setup(void)
44{
45 add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
46}