]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/ppc/kernel/setup.c
Remove obsolete #include <linux/config.h>
[mirror_ubuntu-jammy-kernel.git] / arch / ppc / kernel / setup.c
CommitLineData
1da177e4 1/*
0a26b136 2 * Common prep boot and setup code.
1da177e4
LT
3 */
4
1da177e4
LT
5#include <linux/module.h>
6#include <linux/string.h>
7#include <linux/sched.h>
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/reboot.h>
11#include <linux/delay.h>
12#include <linux/initrd.h>
13#include <linux/ide.h>
14#include <linux/tty.h>
15#include <linux/bootmem.h>
16#include <linux/seq_file.h>
17#include <linux/root_dev.h>
18#include <linux/cpu.h>
19#include <linux/console.h>
20
21#include <asm/residual.h>
22#include <asm/io.h>
23#include <asm/prom.h>
24#include <asm/processor.h>
25#include <asm/pgtable.h>
26#include <asm/bootinfo.h>
27#include <asm/setup.h>
28#include <asm/amigappc.h>
29#include <asm/smp.h>
30#include <asm/elf.h>
31#include <asm/cputable.h>
32#include <asm/bootx.h>
33#include <asm/btext.h>
34#include <asm/machdep.h>
35#include <asm/uaccess.h>
36#include <asm/system.h>
1da177e4
LT
37#include <asm/sections.h>
38#include <asm/nvram.h>
39#include <asm/xmon.h>
40#include <asm/ocp.h>
41
8e8fff09
KG
42#define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
43 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
44 defined(CONFIG_PPC_MPC52xx))
45
46#if USES_PPC_SYS
1da177e4
LT
47#include <asm/ppc_sys.h>
48#endif
49
50#if defined CONFIG_KGDB
51#include <asm/kgdb.h>
52#endif
53
54extern void platform_init(unsigned long r3, unsigned long r4,
55 unsigned long r5, unsigned long r6, unsigned long r7);
1da177e4
LT
56extern void identify_cpu(unsigned long offset, unsigned long cpu);
57extern void do_cpu_ftr_fixups(unsigned long offset);
58extern void reloc_got2(unsigned long offset);
59
60extern void ppc6xx_idle(void);
61extern void power4_idle(void);
62
63extern boot_infos_t *boot_infos;
64struct ide_machdep_calls ppc_ide_md;
1da177e4
LT
65
66/* Used with the BI_MEMSIZE bootinfo parameter to store the memory
67 size value reported by the boot loader. */
68unsigned long boot_mem_size;
69
70unsigned long ISA_DMA_THRESHOLD;
b8f114db
JL
71unsigned int DMA_MODE_READ;
72unsigned int DMA_MODE_WRITE;
1da177e4 73
0a26b136 74#ifdef CONFIG_PPC_PREP
1da177e4
LT
75extern void prep_init(unsigned long r3, unsigned long r4,
76 unsigned long r5, unsigned long r6, unsigned long r7);
14cf11af
PM
77
78dev_t boot_dev;
0a26b136 79#endif /* CONFIG_PPC_PREP */
1da177e4 80
fd582ec8
PM
81int have_of;
82EXPORT_SYMBOL(have_of);
83
35d81a4b
PM
84#ifdef __DO_IRQ_CANON
85int ppc_do_canonicalize_irqs;
86EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
87#endif
88
1da177e4
LT
89#ifdef CONFIG_MAGIC_SYSRQ
90unsigned long SYSRQ_KEY = 0x54;
91#endif /* CONFIG_MAGIC_SYSRQ */
92
93#ifdef CONFIG_VGA_CONSOLE
94unsigned long vgacon_remap_base;
95#endif
96
97struct machdep_calls ppc_md;
98
99/*
100 * These are used in binfmt_elf.c to put aux entries on the stack
101 * for each elf executable being started.
102 */
103int dcache_bsize;
104int icache_bsize;
105int ucache_bsize;
106
107#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
108 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
109struct screen_info screen_info = {
110 0, 25, /* orig-x, orig-y */
111 0, /* unused */
112 0, /* orig-video-page */
113 0, /* orig-video-mode */
114 80, /* orig-video-cols */
115 0,0,0, /* ega_ax, ega_bx, ega_cx */
116 25, /* orig-video-lines */
117 1, /* orig-video-isVGA */
118 16 /* orig-video-points */
119};
120#endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
121
122void machine_restart(char *cmd)
123{
124#ifdef CONFIG_NVRAM
125 nvram_sync();
126#endif
127 ppc_md.restart(cmd);
128}
129
1da177e4
LT
130void machine_power_off(void)
131{
132#ifdef CONFIG_NVRAM
133 nvram_sync();
134#endif
135 ppc_md.power_off();
136}
137
1da177e4
LT
138void machine_halt(void)
139{
140#ifdef CONFIG_NVRAM
141 nvram_sync();
142#endif
143 ppc_md.halt();
144}
145
1da177e4
LT
146void (*pm_power_off)(void) = machine_power_off;
147
148#ifdef CONFIG_TAU
149extern u32 cpu_temp(unsigned long cpu);
150extern u32 cpu_temp_both(unsigned long cpu);
151#endif /* CONFIG_TAU */
152
153int show_cpuinfo(struct seq_file *m, void *v)
154{
155 int i = (int) v - 1;
156 int err = 0;
157 unsigned int pvr;
158 unsigned short maj, min;
159 unsigned long lpj;
160
161 if (i >= NR_CPUS) {
162 /* Show summary information */
163#ifdef CONFIG_SMP
164 unsigned long bogosum = 0;
394e3902
AM
165 for_each_online_cpu(i)
166 bogosum += cpu_data[i].loops_per_jiffy;
1da177e4
LT
167 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
168 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
169#endif /* CONFIG_SMP */
170
171 if (ppc_md.show_cpuinfo != NULL)
172 err = ppc_md.show_cpuinfo(m);
173 return err;
174 }
175
176#ifdef CONFIG_SMP
177 if (!cpu_online(i))
178 return 0;
179 pvr = cpu_data[i].pvr;
180 lpj = cpu_data[i].loops_per_jiffy;
181#else
182 pvr = mfspr(SPRN_PVR);
183 lpj = loops_per_jiffy;
184#endif
185
186 seq_printf(m, "processor\t: %d\n", i);
187 seq_printf(m, "cpu\t\t: ");
188
400d2212
KG
189 if (cur_cpu_spec->pvr_mask)
190 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
1da177e4
LT
191 else
192 seq_printf(m, "unknown (%08x)", pvr);
193#ifdef CONFIG_ALTIVEC
400d2212 194 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
1da177e4
LT
195 seq_printf(m, ", altivec supported");
196#endif
197 seq_printf(m, "\n");
198
199#ifdef CONFIG_TAU
400d2212 200 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
1da177e4
LT
201#ifdef CONFIG_TAU_AVERAGE
202 /* more straightforward, but potentially misleading */
203 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
204 cpu_temp(i));
205#else
206 /* show the actual temp sensor range */
207 u32 temp;
208 temp = cpu_temp_both(i);
209 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
210 temp & 0xff, temp >> 16);
211#endif
212 }
213#endif /* CONFIG_TAU */
214
215 if (ppc_md.show_percpuinfo != NULL) {
216 err = ppc_md.show_percpuinfo(m, i);
217 if (err)
218 return err;
219 }
220
696c2b9f
KG
221 /* If we are a Freescale core do a simple check so
222 * we dont have to keep adding cases in the future */
223 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
1da177e4
LT
224 maj = PVR_MAJ(pvr);
225 min = PVR_MIN(pvr);
696c2b9f
KG
226 } else {
227 switch (PVR_VER(pvr)) {
228 case 0x0020: /* 403 family */
229 maj = PVR_MAJ(pvr) + 1;
230 min = PVR_MIN(pvr);
231 break;
232 case 0x1008: /* 740P/750P ?? */
233 maj = ((pvr >> 8) & 0xFF) - 1;
234 min = pvr & 0xFF;
235 break;
236 default:
237 maj = (pvr >> 8) & 0xFF;
238 min = pvr & 0xFF;
239 break;
240 }
1da177e4
LT
241 }
242
243 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
244 maj, min, PVR_VER(pvr), PVR_REV(pvr));
245
246 seq_printf(m, "bogomips\t: %lu.%02lu\n",
247 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
248
8e8fff09 249#if USES_PPC_SYS
1da177e4
LT
250 if (cur_ppc_sys_spec->ppc_sys_name)
251 seq_printf(m, "chipset\t\t: %s\n",
252 cur_ppc_sys_spec->ppc_sys_name);
253#endif
254
255#ifdef CONFIG_SMP
256 seq_printf(m, "\n");
257#endif
258
259 return 0;
260}
261
262static void *c_start(struct seq_file *m, loff_t *pos)
263{
264 int i = *pos;
265
266 return i <= NR_CPUS? (void *) (i + 1): NULL;
267}
268
269static void *c_next(struct seq_file *m, void *v, loff_t *pos)
270{
271 ++*pos;
272 return c_start(m, pos);
273}
274
275static void c_stop(struct seq_file *m, void *v)
276{
277}
278
279struct seq_operations cpuinfo_op = {
280 .start =c_start,
281 .next = c_next,
282 .stop = c_stop,
283 .show = show_cpuinfo,
284};
285
286/*
287 * We're called here very early in the boot. We determine the machine
288 * type and call the appropriate low-level setup functions.
289 * -- Cort <cort@fsmlabs.com>
290 *
291 * Note that the kernel may be running at an address which is different
292 * from the address that it was linked at, so we must use RELOC/PTRRELOC
293 * to access static data (including strings). -- paulus
294 */
295__init
296unsigned long
297early_init(int r3, int r4, int r5)
298{
299 unsigned long phys;
300 unsigned long offset = reloc_offset();
301
302 /* Default */
303 phys = offset + KERNELBASE;
304
305 /* First zero the BSS -- use memset, some arches don't have
306 * caches on yet */
307 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
308
309 /*
310 * Identify the CPU type and fix up code sections
311 * that depend on which cpu we have.
312 */
313 identify_cpu(offset, 0);
314 do_cpu_ftr_fixups(offset);
315
1da177e4
LT
316 return phys;
317}
318
0a26b136 319#ifdef CONFIG_PPC_PREP
1da177e4 320/*
0a26b136 321 * The PPC_PREP version of platform_init...
1da177e4
LT
322 */
323void __init
324platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
325 unsigned long r6, unsigned long r7)
326{
327#ifdef CONFIG_BOOTX_TEXT
328 if (boot_text_mapped) {
329 btext_clearscreen();
330 btext_welcome();
331 }
332#endif
333
334 parse_bootinfo(find_bootinfo());
335
0a26b136 336 prep_init(r3, r4, r5, r6, r7);
1da177e4 337}
0a26b136 338#endif /* CONFIG_PPC_PREP */
1da177e4
LT
339
340struct bi_record *find_bootinfo(void)
341{
342 struct bi_record *rec;
343
344 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
345 if ( rec->tag != BI_FIRST ) {
346 /*
347 * This 0x10000 offset is a terrible hack but it will go away when
348 * we have the bootloader handle all the relocation and
349 * prom calls -- Cort
350 */
351 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
352 if ( rec->tag != BI_FIRST )
353 return NULL;
354 }
355 return rec;
356}
357
358void parse_bootinfo(struct bi_record *rec)
359{
360 if (rec == NULL || rec->tag != BI_FIRST)
361 return;
362 while (rec->tag != BI_LAST) {
363 ulong *data = rec->data;
364 switch (rec->tag) {
365 case BI_CMD_LINE:
366 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
367 break;
1da177e4
LT
368#ifdef CONFIG_BLK_DEV_INITRD
369 case BI_INITRD:
370 initrd_start = data[0] + KERNELBASE;
371 initrd_end = data[0] + data[1] + KERNELBASE;
372 break;
373#endif /* CONFIG_BLK_DEV_INITRD */
1da177e4
LT
374 case BI_MEMSIZE:
375 boot_mem_size = data[0];
376 break;
377 }
378 rec = (struct bi_record *)((ulong)rec + rec->size);
379 }
380}
381
382/*
383 * Find out what kind of machine we're on and save any data we need
384 * from the early boot process (devtree is copied on pmac by prom_init()).
385 * This is called very early on the boot process, after a minimal
386 * MMU environment has been set up but before MMU_init is called.
387 */
388void __init
389machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
390 unsigned long r6, unsigned long r7)
391{
392#ifdef CONFIG_CMDLINE
393 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
394#endif /* CONFIG_CMDLINE */
395
396#ifdef CONFIG_6xx
397 ppc_md.power_save = ppc6xx_idle;
398#endif
1da177e4
LT
399
400 platform_init(r3, r4, r5, r6, r7);
401
402 if (ppc_md.progress)
403 ppc_md.progress("id mach(): done", 0x200);
404}
a2f40ccd
KG
405#ifdef CONFIG_BOOKE_WDT
406/* Checks wdt=x and wdt_period=xx command-line option */
407int __init early_parse_wdt(char *p)
408{
a2f40ccd 409 if (p && strncmp(p, "0", 1) != 0)
39cdc4bf 410 booke_wdt_enabled = 1;
a2f40ccd
KG
411
412 return 0;
413}
414early_param("wdt", early_parse_wdt);
415
416int __init early_parse_wdt_period (char *p)
417{
a2f40ccd 418 if (p)
39cdc4bf 419 booke_wdt_period = simple_strtoul(p, NULL, 0);
a2f40ccd
KG
420
421 return 0;
422}
423early_param("wdt_period", early_parse_wdt_period);
424#endif /* CONFIG_BOOKE_WDT */
1da177e4
LT
425
426/* Checks "l2cr=xxxx" command-line option */
427int __init ppc_setup_l2cr(char *str)
428{
429 if (cpu_has_feature(CPU_FTR_L2CR)) {
430 unsigned long val = simple_strtoul(str, NULL, 0);
431 printk(KERN_INFO "l2cr set to %lx\n", val);
432 _set_L2CR(0); /* force invalidate by disable cache */
433 _set_L2CR(val); /* and enable it */
434 }
435 return 1;
436}
437__setup("l2cr=", ppc_setup_l2cr);
438
439#ifdef CONFIG_GENERIC_NVRAM
440
441/* Generic nvram hooks used by drivers/char/gen_nvram.c */
442unsigned char nvram_read_byte(int addr)
443{
444 if (ppc_md.nvram_read_val)
445 return ppc_md.nvram_read_val(addr);
446 return 0xff;
447}
448EXPORT_SYMBOL(nvram_read_byte);
449
450void nvram_write_byte(unsigned char val, int addr)
451{
452 if (ppc_md.nvram_write_val)
453 ppc_md.nvram_write_val(addr, val);
454}
455EXPORT_SYMBOL(nvram_write_byte);
456
457void nvram_sync(void)
458{
459 if (ppc_md.nvram_sync)
460 ppc_md.nvram_sync();
461}
462EXPORT_SYMBOL(nvram_sync);
463
464#endif /* CONFIG_NVRAM */
465
466static struct cpu cpu_devices[NR_CPUS];
467
468int __init ppc_init(void)
469{
470 int i;
471
472 /* clear the progress line */
473 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
474
475 /* register CPU devices */
b848e0a0 476 for_each_possible_cpu(i)
76b67ed9 477 register_cpu(&cpu_devices[i], i);
1da177e4
LT
478
479 /* call platform init */
480 if (ppc_md.init != NULL) {
481 ppc_md.init();
482 }
483 return 0;
484}
485
486arch_initcall(ppc_init);
487
488/* Warning, IO base is not yet inited */
489void __init setup_arch(char **cmdline_p)
490{
491 extern char *klimit;
492 extern void do_init_bootmem(void);
493
494 /* so udelay does something sensible, assume <= 1000 bogomips */
495 loops_per_jiffy = 500000000 / HZ;
496
51d3082f
BH
497 if (ppc_md.init_early)
498 ppc_md.init_early();
499
1da177e4 500#ifdef CONFIG_XMON
fd582ec8 501 xmon_init(1);
1da177e4
LT
502 if (strstr(cmd_line, "xmon"))
503 xmon(NULL);
504#endif /* CONFIG_XMON */
505 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
506
507#if defined(CONFIG_KGDB)
508 if (ppc_md.kgdb_map_scc)
509 ppc_md.kgdb_map_scc();
510 set_debug_traps();
511 if (strstr(cmd_line, "gdb")) {
512 if (ppc_md.progress)
513 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
514 printk("kgdb breakpoint activated\n");
515 breakpoint();
516 }
517#endif
518
519 /*
520 * Set cache line size based on type of cpu as a default.
521 * Systems with OF can look in the properties on the cpu node(s)
522 * for a possibly more accurate value.
523 */
524 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
400d2212
KG
525 dcache_bsize = cur_cpu_spec->dcache_bsize;
526 icache_bsize = cur_cpu_spec->icache_bsize;
1da177e4
LT
527 ucache_bsize = 0;
528 } else
529 ucache_bsize = dcache_bsize = icache_bsize
400d2212 530 = cur_cpu_spec->dcache_bsize;
1da177e4
LT
531
532 /* reboot on panic */
533 panic_timeout = 180;
534
535 init_mm.start_code = PAGE_OFFSET;
536 init_mm.end_code = (unsigned long) _etext;
537 init_mm.end_data = (unsigned long) _edata;
538 init_mm.brk = (unsigned long) klimit;
539
540 /* Save unparsed command line copy for /proc/cmdline */
541 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
542 *cmdline_p = cmd_line;
543
19bbdf0e
PM
544 parse_early_param();
545
1da177e4
LT
546 /* set up the bootmem stuff with available memory */
547 do_init_bootmem();
548 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
549
550#ifdef CONFIG_PPC_OCP
551 /* Initialize OCP device list */
552 ocp_early_init();
553 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
554#endif
555
556#ifdef CONFIG_DUMMY_CONSOLE
557 conswitchp = &dummy_con;
558#endif
559
560 ppc_md.setup_arch();
561 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
562
563 paging_init();
1da177e4 564}