Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/arch/unicore32/kernel/setup.c
10817 views
1
/*
2
* linux/arch/unicore32/kernel/setup.c
3
*
4
* Code specific to PKUnity SoC and UniCore ISA
5
*
6
* Copyright (C) 2001-2010 GUAN Xue-tao
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
11
*/
12
#include <linux/module.h>
13
#include <linux/kernel.h>
14
#include <linux/stddef.h>
15
#include <linux/ioport.h>
16
#include <linux/delay.h>
17
#include <linux/utsname.h>
18
#include <linux/initrd.h>
19
#include <linux/console.h>
20
#include <linux/bootmem.h>
21
#include <linux/seq_file.h>
22
#include <linux/screen_info.h>
23
#include <linux/init.h>
24
#include <linux/root_dev.h>
25
#include <linux/cpu.h>
26
#include <linux/interrupt.h>
27
#include <linux/smp.h>
28
#include <linux/fs.h>
29
#include <linux/proc_fs.h>
30
#include <linux/memblock.h>
31
#include <linux/elf.h>
32
#include <linux/io.h>
33
34
#include <asm/cputype.h>
35
#include <asm/sections.h>
36
#include <asm/setup.h>
37
#include <asm/cacheflush.h>
38
#include <asm/tlbflush.h>
39
#include <asm/traps.h>
40
41
#include "setup.h"
42
43
#ifndef MEM_SIZE
44
#define MEM_SIZE (16*1024*1024)
45
#endif
46
47
struct stack {
48
u32 irq[3];
49
u32 abt[3];
50
u32 und[3];
51
} ____cacheline_aligned;
52
53
static struct stack stacks[NR_CPUS];
54
55
char elf_platform[ELF_PLATFORM_SIZE];
56
EXPORT_SYMBOL(elf_platform);
57
58
static char __initdata cmd_line[COMMAND_LINE_SIZE];
59
60
static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
61
62
/*
63
* Standard memory resources
64
*/
65
static struct resource mem_res[] = {
66
{
67
.name = "Kernel text",
68
.start = 0,
69
.end = 0,
70
.flags = IORESOURCE_MEM
71
},
72
{
73
.name = "Kernel data",
74
.start = 0,
75
.end = 0,
76
.flags = IORESOURCE_MEM
77
}
78
};
79
80
#define kernel_code mem_res[0]
81
#define kernel_data mem_res[1]
82
83
/*
84
* These functions re-use the assembly code in head.S, which
85
* already provide the required functionality.
86
*/
87
static void __init setup_processor(void)
88
{
89
printk(KERN_DEFAULT "CPU: UniCore-II [%08x] revision %d, cr=%08lx\n",
90
uc32_cpuid, (int)(uc32_cpuid >> 16) & 15, cr_alignment);
91
92
sprintf(init_utsname()->machine, "puv3");
93
sprintf(elf_platform, "ucv2");
94
}
95
96
/*
97
* cpu_init - initialise one CPU.
98
*
99
* cpu_init sets up the per-CPU stacks.
100
*/
101
void cpu_init(void)
102
{
103
unsigned int cpu = smp_processor_id();
104
struct stack *stk = &stacks[cpu];
105
106
/*
107
* setup stacks for re-entrant exception handlers
108
*/
109
__asm__ (
110
"mov.a asr, %1\n\t"
111
"add sp, %0, %2\n\t"
112
"mov.a asr, %3\n\t"
113
"add sp, %0, %4\n\t"
114
"mov.a asr, %5\n\t"
115
"add sp, %0, %6\n\t"
116
"mov.a asr, %7"
117
:
118
: "r" (stk),
119
"r" (PSR_R_BIT | PSR_I_BIT | INTR_MODE),
120
"I" (offsetof(struct stack, irq[0])),
121
"r" (PSR_R_BIT | PSR_I_BIT | ABRT_MODE),
122
"I" (offsetof(struct stack, abt[0])),
123
"r" (PSR_R_BIT | PSR_I_BIT | EXTN_MODE),
124
"I" (offsetof(struct stack, und[0])),
125
"r" (PSR_R_BIT | PSR_I_BIT | PRIV_MODE)
126
: "r30", "cc");
127
}
128
129
static int __init uc32_add_memory(unsigned long start, unsigned long size)
130
{
131
struct membank *bank = &meminfo.bank[meminfo.nr_banks];
132
133
if (meminfo.nr_banks >= NR_BANKS) {
134
printk(KERN_CRIT "NR_BANKS too low, "
135
"ignoring memory at %#lx\n", start);
136
return -EINVAL;
137
}
138
139
/*
140
* Ensure that start/size are aligned to a page boundary.
141
* Size is appropriately rounded down, start is rounded up.
142
*/
143
size -= start & ~PAGE_MASK;
144
145
bank->start = PAGE_ALIGN(start);
146
bank->size = size & PAGE_MASK;
147
148
/*
149
* Check whether this memory region has non-zero size or
150
* invalid node number.
151
*/
152
if (bank->size == 0)
153
return -EINVAL;
154
155
meminfo.nr_banks++;
156
return 0;
157
}
158
159
/*
160
* Pick out the memory size. We look for mem=size@start,
161
* where start and size are "size[KkMm]"
162
*/
163
static int __init early_mem(char *p)
164
{
165
static int usermem __initdata = 1;
166
unsigned long size, start;
167
char *endp;
168
169
/*
170
* If the user specifies memory size, we
171
* blow away any automatically generated
172
* size.
173
*/
174
if (usermem) {
175
usermem = 0;
176
meminfo.nr_banks = 0;
177
}
178
179
start = PHYS_OFFSET;
180
size = memparse(p, &endp);
181
if (*endp == '@')
182
start = memparse(endp + 1, NULL);
183
184
uc32_add_memory(start, size);
185
186
return 0;
187
}
188
early_param("mem", early_mem);
189
190
static void __init
191
request_standard_resources(struct meminfo *mi)
192
{
193
struct resource *res;
194
int i;
195
196
kernel_code.start = virt_to_phys(_stext);
197
kernel_code.end = virt_to_phys(_etext - 1);
198
kernel_data.start = virt_to_phys(_sdata);
199
kernel_data.end = virt_to_phys(_end - 1);
200
201
for (i = 0; i < mi->nr_banks; i++) {
202
if (mi->bank[i].size == 0)
203
continue;
204
205
res = alloc_bootmem_low(sizeof(*res));
206
res->name = "System RAM";
207
res->start = mi->bank[i].start;
208
res->end = mi->bank[i].start + mi->bank[i].size - 1;
209
res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
210
211
request_resource(&iomem_resource, res);
212
213
if (kernel_code.start >= res->start &&
214
kernel_code.end <= res->end)
215
request_resource(res, &kernel_code);
216
if (kernel_data.start >= res->start &&
217
kernel_data.end <= res->end)
218
request_resource(res, &kernel_data);
219
}
220
}
221
222
static void (*init_machine)(void) __initdata;
223
224
static int __init customize_machine(void)
225
{
226
/* customizes platform devices, or adds new ones */
227
if (init_machine)
228
init_machine();
229
return 0;
230
}
231
arch_initcall(customize_machine);
232
233
void __init setup_arch(char **cmdline_p)
234
{
235
char *from = default_command_line;
236
237
setup_processor();
238
239
init_mm.start_code = (unsigned long) _stext;
240
init_mm.end_code = (unsigned long) _etext;
241
init_mm.end_data = (unsigned long) _edata;
242
init_mm.brk = (unsigned long) _end;
243
244
/* parse_early_param needs a boot_command_line */
245
strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
246
247
/* populate cmd_line too for later use, preserving boot_command_line */
248
strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
249
*cmdline_p = cmd_line;
250
251
parse_early_param();
252
253
uc32_memblock_init(&meminfo);
254
255
paging_init();
256
request_standard_resources(&meminfo);
257
258
cpu_init();
259
260
/*
261
* Set up various architecture-specific pointers
262
*/
263
init_machine = puv3_core_init;
264
265
#ifdef CONFIG_VT
266
#if defined(CONFIG_VGA_CONSOLE)
267
conswitchp = &vga_con;
268
#elif defined(CONFIG_DUMMY_CONSOLE)
269
conswitchp = &dummy_con;
270
#endif
271
#endif
272
early_trap_init();
273
}
274
275
static struct cpu cpuinfo_unicore;
276
277
static int __init topology_init(void)
278
{
279
int i;
280
281
for_each_possible_cpu(i)
282
register_cpu(&cpuinfo_unicore, i);
283
284
return 0;
285
}
286
subsys_initcall(topology_init);
287
288
#ifdef CONFIG_HAVE_PROC_CPU
289
static int __init proc_cpu_init(void)
290
{
291
struct proc_dir_entry *res;
292
293
res = proc_mkdir("cpu", NULL);
294
if (!res)
295
return -ENOMEM;
296
return 0;
297
}
298
fs_initcall(proc_cpu_init);
299
#endif
300
301
static int c_show(struct seq_file *m, void *v)
302
{
303
seq_printf(m, "Processor\t: UniCore-II rev %d (%s)\n",
304
(int)(uc32_cpuid >> 16) & 15, elf_platform);
305
306
seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
307
loops_per_jiffy / (500000/HZ),
308
(loops_per_jiffy / (5000/HZ)) % 100);
309
310
/* dump out the processor features */
311
seq_puts(m, "Features\t: CMOV UC-F64");
312
313
seq_printf(m, "\nCPU implementer\t: 0x%02x\n", uc32_cpuid >> 24);
314
seq_printf(m, "CPU architecture: 2\n");
315
seq_printf(m, "CPU revision\t: %d\n", (uc32_cpuid >> 16) & 15);
316
317
seq_printf(m, "Cache type\t: write-back\n"
318
"Cache clean\t: cp0 c5 ops\n"
319
"Cache lockdown\t: not support\n"
320
"Cache format\t: Harvard\n");
321
322
seq_puts(m, "\n");
323
324
seq_printf(m, "Hardware\t: PKUnity v3\n");
325
326
return 0;
327
}
328
329
static void *c_start(struct seq_file *m, loff_t *pos)
330
{
331
return *pos < 1 ? (void *)1 : NULL;
332
}
333
334
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
335
{
336
++*pos;
337
return NULL;
338
}
339
340
static void c_stop(struct seq_file *m, void *v)
341
{
342
}
343
344
const struct seq_operations cpuinfo_op = {
345
.start = c_start,
346
.next = c_next,
347
.stop = c_stop,
348
.show = c_show
349
};
350
351