treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / unicore32 / kernel / setup.c
blob0c4242a5ee1d48e5fa457a9b97a8a119d6b47cf1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/unicore32/kernel/setup.c
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
8 */
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/stddef.h>
12 #include <linux/ioport.h>
13 #include <linux/delay.h>
14 #include <linux/utsname.h>
15 #include <linux/initrd.h>
16 #include <linux/console.h>
17 #include <linux/memblock.h>
18 #include <linux/seq_file.h>
19 #include <linux/screen_info.h>
20 #include <linux/init.h>
21 #include <linux/root_dev.h>
22 #include <linux/cpu.h>
23 #include <linux/interrupt.h>
24 #include <linux/smp.h>
25 #include <linux/fs.h>
26 #include <linux/proc_fs.h>
27 #include <linux/elf.h>
28 #include <linux/io.h>
30 #include <asm/cputype.h>
31 #include <asm/sections.h>
32 #include <asm/setup.h>
33 #include <asm/cacheflush.h>
34 #include <asm/tlbflush.h>
35 #include <asm/traps.h>
36 #include <asm/memblock.h>
38 #include "setup.h"
40 #ifndef MEM_SIZE
41 #define MEM_SIZE (16*1024*1024)
42 #endif
44 struct stack {
45 u32 irq[3];
46 u32 abt[3];
47 u32 und[3];
48 } ____cacheline_aligned;
50 static struct stack stacks[NR_CPUS];
52 #ifdef CONFIG_VGA_CONSOLE
53 struct screen_info screen_info;
54 #endif
56 char elf_platform[ELF_PLATFORM_SIZE];
57 EXPORT_SYMBOL(elf_platform);
59 static char __initdata cmd_line[COMMAND_LINE_SIZE];
61 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
64 * Standard memory resources
66 static struct resource mem_res[] = {
68 .name = "Kernel code",
69 .start = 0,
70 .end = 0,
71 .flags = IORESOURCE_SYSTEM_RAM
74 .name = "Kernel data",
75 .start = 0,
76 .end = 0,
77 .flags = IORESOURCE_SYSTEM_RAM
81 #define kernel_code mem_res[0]
82 #define kernel_data mem_res[1]
85 * These functions re-use the assembly code in head.S, which
86 * already provide the required functionality.
88 static void __init setup_processor(void)
90 printk(KERN_DEFAULT "CPU: UniCore-II [%08x] revision %d, cr=%08lx\n",
91 uc32_cpuid, (int)(uc32_cpuid >> 16) & 15, cr_alignment);
93 sprintf(init_utsname()->machine, "puv3");
94 sprintf(elf_platform, "ucv2");
98 * cpu_init - initialise one CPU.
100 * cpu_init sets up the per-CPU stacks.
102 void cpu_init(void)
104 unsigned int cpu = smp_processor_id();
105 struct stack *stk = &stacks[cpu];
108 * setup stacks for re-entrant exception handlers
110 __asm__ (
111 "mov.a asr, %1\n\t"
112 "add sp, %0, %2\n\t"
113 "mov.a asr, %3\n\t"
114 "add sp, %0, %4\n\t"
115 "mov.a asr, %5\n\t"
116 "add sp, %0, %6\n\t"
117 "mov.a asr, %7"
119 : "r" (stk),
120 "r" (PSR_R_BIT | PSR_I_BIT | INTR_MODE),
121 "I" (offsetof(struct stack, irq[0])),
122 "r" (PSR_R_BIT | PSR_I_BIT | ABRT_MODE),
123 "I" (offsetof(struct stack, abt[0])),
124 "r" (PSR_R_BIT | PSR_I_BIT | EXTN_MODE),
125 "I" (offsetof(struct stack, und[0])),
126 "r" (PSR_R_BIT | PSR_I_BIT | PRIV_MODE)
127 : "r30", "cc");
130 static int __init uc32_add_memory(unsigned long start, unsigned long size)
132 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
134 if (meminfo.nr_banks >= NR_BANKS) {
135 printk(KERN_CRIT "NR_BANKS too low, "
136 "ignoring memory at %#lx\n", start);
137 return -EINVAL;
141 * Ensure that start/size are aligned to a page boundary.
142 * Size is appropriately rounded down, start is rounded up.
144 size -= start & ~PAGE_MASK;
146 bank->start = PAGE_ALIGN(start);
147 bank->size = size & PAGE_MASK;
150 * Check whether this memory region has non-zero size or
151 * invalid node number.
153 if (bank->size == 0)
154 return -EINVAL;
156 meminfo.nr_banks++;
157 return 0;
161 * Pick out the memory size. We look for mem=size@start,
162 * where start and size are "size[KkMm]"
164 static int __init early_mem(char *p)
166 static int usermem __initdata = 1;
167 unsigned long size, start;
168 char *endp;
171 * If the user specifies memory size, we
172 * blow away any automatically generated
173 * size.
175 if (usermem) {
176 usermem = 0;
177 meminfo.nr_banks = 0;
180 start = PHYS_OFFSET;
181 size = memparse(p, &endp);
182 if (*endp == '@')
183 start = memparse(endp + 1, NULL);
185 uc32_add_memory(start, size);
187 return 0;
189 early_param("mem", early_mem);
191 static void __init
192 request_standard_resources(struct meminfo *mi)
194 struct resource *res;
195 int i;
197 kernel_code.start = virt_to_phys(_stext);
198 kernel_code.end = virt_to_phys(_etext - 1);
199 kernel_data.start = virt_to_phys(_sdata);
200 kernel_data.end = virt_to_phys(_end - 1);
202 for (i = 0; i < mi->nr_banks; i++) {
203 if (mi->bank[i].size == 0)
204 continue;
206 res = memblock_alloc_low(sizeof(*res), SMP_CACHE_BYTES);
207 if (!res)
208 panic("%s: Failed to allocate %zu bytes align=%x\n",
209 __func__, sizeof(*res), SMP_CACHE_BYTES);
211 res->name = "System RAM";
212 res->start = mi->bank[i].start;
213 res->end = mi->bank[i].start + mi->bank[i].size - 1;
214 res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
216 request_resource(&iomem_resource, res);
218 if (kernel_code.start >= res->start &&
219 kernel_code.end <= res->end)
220 request_resource(res, &kernel_code);
221 if (kernel_data.start >= res->start &&
222 kernel_data.end <= res->end)
223 request_resource(res, &kernel_data);
227 static void (*init_machine)(void) __initdata;
229 static int __init customize_machine(void)
231 /* customizes platform devices, or adds new ones */
232 if (init_machine)
233 init_machine();
234 return 0;
236 arch_initcall(customize_machine);
238 void __init setup_arch(char **cmdline_p)
240 char *from = default_command_line;
242 setup_processor();
244 init_mm.start_code = (unsigned long) _stext;
245 init_mm.end_code = (unsigned long) _etext;
246 init_mm.end_data = (unsigned long) _edata;
247 init_mm.brk = (unsigned long) _end;
249 /* parse_early_param needs a boot_command_line */
250 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
252 /* populate cmd_line too for later use, preserving boot_command_line */
253 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
254 *cmdline_p = cmd_line;
256 parse_early_param();
258 uc32_memblock_init(&meminfo);
260 paging_init();
261 request_standard_resources(&meminfo);
263 cpu_init();
266 * Set up various architecture-specific pointers
268 init_machine = puv3_core_init;
270 #ifdef CONFIG_VT
271 #if defined(CONFIG_VGA_CONSOLE)
272 conswitchp = &vga_con;
273 #endif
274 #endif
275 early_trap_init();
278 static struct cpu cpuinfo_unicore;
280 static int __init topology_init(void)
282 int i;
284 for_each_possible_cpu(i)
285 register_cpu(&cpuinfo_unicore, i);
287 return 0;
289 subsys_initcall(topology_init);
291 #ifdef CONFIG_HAVE_PROC_CPU
292 static int __init proc_cpu_init(void)
294 struct proc_dir_entry *res;
296 res = proc_mkdir("cpu", NULL);
297 if (!res)
298 return -ENOMEM;
299 return 0;
301 fs_initcall(proc_cpu_init);
302 #endif
304 static int c_show(struct seq_file *m, void *v)
306 seq_printf(m, "Processor\t: UniCore-II rev %d (%s)\n",
307 (int)(uc32_cpuid >> 16) & 15, elf_platform);
309 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
310 loops_per_jiffy / (500000/HZ),
311 (loops_per_jiffy / (5000/HZ)) % 100);
313 /* dump out the processor features */
314 seq_puts(m, "Features\t: CMOV UC-F64");
316 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", uc32_cpuid >> 24);
317 seq_printf(m, "CPU architecture: 2\n");
318 seq_printf(m, "CPU revision\t: %d\n", (uc32_cpuid >> 16) & 15);
320 seq_printf(m, "Cache type\t: write-back\n"
321 "Cache clean\t: cp0 c5 ops\n"
322 "Cache lockdown\t: not support\n"
323 "Cache format\t: Harvard\n");
325 seq_puts(m, "\n");
327 seq_printf(m, "Hardware\t: PKUnity v3\n");
329 return 0;
332 static void *c_start(struct seq_file *m, loff_t *pos)
334 return *pos < 1 ? (void *)1 : NULL;
337 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
339 ++*pos;
340 return NULL;
343 static void c_stop(struct seq_file *m, void *v)
347 const struct seq_operations cpuinfo_op = {
348 .start = c_start,
349 .next = c_next,
350 .stop = c_stop,
351 .show = c_show