2 * $Id: setup.c,v 1.160 1999/10/08 01:56:38 paulus Exp $
3 * Common prep/pmac/chrp boot and setup code.
6 #include <linux/config.h>
7 #include <linux/module.h>
8 #include <linux/string.h>
9 #include <linux/sched.h>
10 #include <linux/init.h>
11 #include <linux/reboot.h>
12 #include <linux/delay.h>
13 #include <linux/blk.h>
14 #include <linux/ide.h>
17 #include <asm/residual.h>
20 #include <asm/processor.h>
21 #include <asm/pgtable.h>
22 #include <asm/bootinfo.h>
23 #include <asm/setup.h>
24 #include <asm/amigappc.h>
27 #include <asm/mpc8xx.h>
28 #include <asm/8xx_immap.h>
30 #include <asm/bootx.h>
31 #include <asm/machdep.h>
33 #include "oak_setup.h"
34 #endif /* CONFIG_OAK */
36 extern void pmac_init(unsigned long r3
,
42 extern void chrp_init(unsigned long r3
,
48 extern void prep_init(unsigned long r3
,
54 extern void m8xx_init(unsigned long r3
,
60 extern void apus_init(unsigned long r3
,
66 extern void gemini_init(unsigned long r3
,
72 #ifdef CONFIG_BOOTX_TEXT
73 extern void map_bootx_text(void);
76 extern void xmon_map_scc(void);
79 extern boot_infos_t
*boot_infos
;
80 char saved_command_line
[256];
81 unsigned char aux_device_present
;
82 struct int_control_struct int_control
=
86 __no_use_restore_flags
,
89 struct ide_machdep_calls ppc_ide_md
;
90 int parse_bootinfo(void);
92 unsigned long ISA_DMA_THRESHOLD
;
93 unsigned long DMA_MODE_READ
, DMA_MODE_WRITE
;
95 #ifndef CONFIG_MACH_SPECIFIC
98 #endif /* CONFIG_MACH_SPECIFIC */
100 #ifdef CONFIG_MAGIC_SYSRQ
101 unsigned long SYSRQ_KEY
;
102 #endif /* CONFIG_MAGIC_SYSRQ */
104 struct machdep_calls ppc_md
;
107 * Perhaps we can put the pmac screen_info[] here
108 * on pmac as well so we don't need the ifdef's.
109 * Until we get multiple-console support in here
112 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
113 struct screen_info screen_info
= {
114 0, 25, /* orig-x, orig-y */
116 0, /* orig-video-page */
117 0, /* orig-video-mode */
118 80, /* orig-video-cols */
119 0,0,0, /* ega_ax, ega_bx, ega_cx */
120 25, /* orig-video-lines */
121 1, /* orig-video-isVGA */
122 16 /* orig-video-points */
126 * I really need to add multiple-console support... -- Cort
128 int __init
pmac_display_supported(char *name
)
132 void __init
pmac_find_display(void)
136 #else /* CONFIG_4xx || CONFIG_8xx */
138 /* We need this to satisfy some external references until we can
139 * strip the kernel down.
141 struct screen_info screen_info
= {
142 0, 25, /* orig-x, orig-y */
144 0, /* orig-video-page */
145 0, /* orig-video-mode */
146 80, /* orig-video-cols */
147 0,0,0, /* ega_ax, ega_bx, ega_cx */
148 25, /* orig-video-lines */
149 0, /* orig-video-isVGA */
150 16 /* orig-video-points */
152 #endif /* !CONFIG_4xx && !CONFIG_8xx */
154 void machine_restart(char *cmd
)
159 void machine_power_off(void)
164 void machine_halt(void)
169 unsigned long cpu_temp(void)
171 unsigned char thres
= 0;
176 /* threshold 0 C, tid: exceeding threshold, tie: don't generate interrupt */
177 _set_THRM1( THRM1_V
);
179 /* we need 20us to do the compare - assume 300MHz processor clock */
181 _set_THRM3(THRM3_E
| (300*30)<<18 );
184 /* wait for the compare to complete */
185 /*while ( !(_get_THRM1() & THRM1_TIV) ) ;*/
186 if ( !(_get_THRM1() & THRM1_TIV
) )
188 if ( _get_THRM1() & THRM1_TIN
)
190 /* turn everything off */
198 int get_cpuinfo(char *buffer
)
200 unsigned long len
= 0;
201 unsigned long bogosum
= 0;
204 unsigned short maj
, min
;
207 #define CPU_PRESENT(x) (cpu_callin_map[(x)])
208 #define GET_PVR ((long int)(cpu_data[i].pvr))
209 #define CD(x) (cpu_data[i].x)
211 #define CPU_PRESENT(x) ((x)==0)
212 #define smp_num_cpus 1
213 #define GET_PVR ((long int)_get_PVR())
217 for ( i
= 0; i
< smp_num_cpus
; i
++ )
219 if ( !CPU_PRESENT(i
) )
222 len
+= sprintf(len
+buffer
,"\n");
223 len
+= sprintf(len
+buffer
,"processor\t: %lu\n",i
);
224 len
+= sprintf(len
+buffer
,"cpu\t\t: ");
228 switch (PVR_VER(pvr
))
231 len
+= sprintf(len
+buffer
, "601\n");
234 len
+= sprintf(len
+buffer
, "603\n");
237 len
+= sprintf(len
+buffer
, "604\n");
240 len
+= sprintf(len
+buffer
, "603e\n");
243 len
+= sprintf(len
+buffer
, "603");
244 if (((pvr
>> 12) & 0xF) == 1) {
245 pvr
^= 0x00001000; /* revision fix-up */
246 len
+= sprintf(len
+buffer
, "r\n");
248 len
+= sprintf(len
+buffer
, "ev\n");
251 case 0x0008: /* 740/750(P) */
253 len
+= sprintf(len
+buffer
, "750%s\n",
254 PVR_VER(pvr
) == 0x1008 ? "P" : "");
255 len
+= sprintf(len
+buffer
, "temperature \t: %lu C\n",
258 case 0x0009: /* 604e/604r */
260 len
+= sprintf(len
+buffer
, "604");
262 if (PVR_VER(pvr
) == 0x000A ||
263 ((pvr
>> 12) & 0xF) != 0) {
264 pvr
&= ~0x00003000; /* revision fix-up */
265 len
+= sprintf(len
+buffer
, "r\n");
267 len
+= sprintf(len
+buffer
, "e\n");
271 len
+= sprintf(len
+buffer
, "7400 (G4)\n");
274 len
+= sprintf(len
+buffer
, "403G");
275 switch ((pvr
>> 8) & 0xFF) {
277 len
+= sprintf(len
+buffer
, "C\n");
280 len
+= sprintf(len
+buffer
, "CX\n");
285 len
+= sprintf(len
+buffer
, "821\n");
288 len
+= sprintf(len
+buffer
, "8240\n");
291 len
+= sprintf(len
+buffer
, "405GP\n");
294 len
+= sprintf(len
+buffer
, "unknown (%08x)\n", pvr
);
299 * Assume here that all clock rates are the same in a
300 * smp system. -- Cort
302 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
305 struct device_node
*cpu_node
;
308 cpu_node
= find_type_devices("cpu");
309 if ( !cpu_node
) break;
312 for ( s
= 0; (s
< i
) && cpu_node
->next
;
313 s
++, cpu_node
= cpu_node
->next
)
315 #if 0 /* SMP Pmacs don't have all cpu nodes -- Cort */
317 printk("get_cpuinfo(): ran out of "
321 fp
= (int *) get_property(cpu_node
, "clock-frequency", NULL
);
323 len
+= sprintf(len
+buffer
, "clock\t\t: %dMHz\n",
326 #endif /* !CONFIG_4xx && !CONFIG_8xx */
328 if (ppc_md
.setup_residual
!= NULL
)
330 len
+= ppc_md
.setup_residual(buffer
+ len
);
333 switch (PVR_VER(pvr
))
336 maj
= PVR_MAJ(pvr
) + 1;
340 maj
= ((pvr
>> 8) & 0xFF) - 1;
344 maj
= (pvr
>> 8) & 0xFF;
349 len
+= sprintf(len
+buffer
, "revision\t: %hd.%hd\n", maj
, min
);
351 len
+= sprintf(buffer
+len
, "bogomips\t: %lu.%02lu\n",
352 (CD(loops_per_sec
)+2500)/500000,
353 (CD(loops_per_sec
)+2500)/5000 % 100);
354 bogosum
+= CD(loops_per_sec
);
359 len
+= sprintf(buffer
+len
, "\n");
360 len
+= sprintf(buffer
+len
,"total bogomips\t: %lu.%02lu\n",
361 (bogosum
+2500)/500000,
362 (bogosum
+2500)/5000 % 100);
366 * Ooh's and aah's info about zero'd pages in idle task
368 len
+= sprintf(buffer
+len
,"zero pages\t: total: %u (%luKb) "
369 "current: %u (%luKb) hits: %u/%u (%u%%)\n",
370 atomic_read(&zero_cache_total
),
371 (atomic_read(&zero_cache_total
)*PAGE_SIZE
)>>10,
372 atomic_read(&zero_cache_sz
),
373 (atomic_read(&zero_cache_sz
)*PAGE_SIZE
)>>10,
374 atomic_read(&zero_cache_hits
),atomic_read(&zero_cache_calls
),
375 /* : 1 below is so we don't div by zero */
376 (atomic_read(&zero_cache_hits
)*100) /
377 ((atomic_read(&zero_cache_calls
))?atomic_read(&zero_cache_calls
):1));
379 if (ppc_md
.get_cpuinfo
!= NULL
)
381 len
+= ppc_md
.get_cpuinfo(buffer
+len
);
387 #ifndef CONFIG_MACH_SPECIFIC
389 intuit_machine_type(void)
392 struct device_node
*root
;
394 /* ask the OF info if we're a chrp or pmac */
395 root
= find_path_device("/");
397 /* assume pmac unless proven to be chrp -- Cort */
398 _machine
= _MACH_Pmac
;
399 model
= get_property(root
, "device_type", NULL
);
400 if (model
&& !strncmp("chrp", model
, 4))
401 _machine
= _MACH_chrp
;
403 model
= get_property(root
, "model", NULL
);
404 if (model
&& !strncmp(model
, "IBM", 3))
405 _machine
= _MACH_chrp
;
409 #endif /* CONFIG_MACH_SPECIFIC */
412 * Find out what kind of machine we're on and save any data we need
413 * from the early boot process (devtree is copied on pmac by prom_init() )
416 identify_machine(unsigned long r3
, unsigned long r4
, unsigned long r5
,
417 unsigned long r6
, unsigned long r7
)
421 if ( ppc_md
.progress
) ppc_md
.progress("id mach(): start", 0x100);
423 #if !defined(CONFIG_4xx) && !defined(CONFIG_8xx)
424 #ifndef CONFIG_MACH_SPECIFIC
425 /* if we didn't get any bootinfo telling us what we are... */
428 /* boot loader will tell us if we're APUS */
429 if ( r3
== 0x61707573 )
431 _machine
= _MACH_apus
;
434 /* prep boot loader tells us if we're prep or not */
435 else if ( *(unsigned long *)(KERNELBASE
) == (0xdeadc0de) )
437 _machine
= _MACH_prep
;
441 #endif /* CONFIG_MACH_SPECIFIC */
445 /* prom_init has already been called from __start */
448 #ifndef CONFIG_MACH_SPECIFIC
449 /* we need to set _machine before calling finish_device_tree */
451 intuit_machine_type();
452 #endif /* CONFIG_MACH_SPECIFIC */
453 finish_device_tree();
456 * If we were booted via quik, r3 points to the physical
457 * address of the command-line parameters.
458 * If we were booted from an xcoff image (i.e. netbooted or
459 * booted from floppy), we get the command line from the
460 * bootargs property of the /chosen node.
461 * If an initial ramdisk is present, r3 and r4
462 * are used for initrd_start and initrd_size,
463 * otherwise they contain 0xdeadbeef.
466 if (r3
>= 0x4000 && r3
< 0x800000 && r4
== 0) {
467 strncpy(cmd_line
, (char *)r3
+ KERNELBASE
,
469 } else if (boot_infos
!= 0) {
470 /* booted by BootX - check for ramdisk */
471 if (boot_infos
->kernelParamsOffset
!= 0)
472 strncpy(cmd_line
, (char *) boot_infos
473 + boot_infos
->kernelParamsOffset
,
475 #ifdef CONFIG_BLK_DEV_INITRD
476 if (boot_infos
->ramDisk
) {
477 initrd_start
= (unsigned long) boot_infos
478 + boot_infos
->ramDisk
;
479 initrd_end
= initrd_start
+ boot_infos
->ramDiskSize
;
480 initrd_below_start_ok
= 1;
484 struct device_node
*chosen
;
487 #ifdef CONFIG_BLK_DEV_INITRD
488 if (r3
&& r4
&& r4
!= 0xdeadbeef)
491 initrd_end
= r3
+ r4
;
492 ROOT_DEV
= MKDEV(RAMDISK_MAJOR
, 0);
493 initrd_below_start_ok
= 1;
497 chosen
= find_devices("chosen");
498 if (chosen
!= NULL
) {
499 p
= get_property(chosen
, "bootargs", NULL
);
501 strncpy(cmd_line
, p
, sizeof(cmd_line
));
504 cmd_line
[sizeof(cmd_line
) - 1] = 0;
510 pmac_init(r3
, r4
, r5
, r6
, r7
);
513 prep_init(r3
, r4
, r5
, r6
, r7
);
516 chrp_init(r3
, r4
, r5
, r6
, r7
);
520 apus_init(r3
, r4
, r5
, r6
, r7
);
525 gemini_init(r3
, r4
, r5
, r6
, r7
);
529 printk("Unknown machine type in identify_machine!\n");
532 /* Check for nobats option (used in mapin_ram). */
533 if (strstr(cmd_line
, "nobats")) {
534 extern int __map_without_bats
;
535 __map_without_bats
= 1;
538 #if defined(CONFIG_4xx)
539 oak_init(r3
, r4
, r5
, r6
, r7
);
540 #elif defined(CONFIG_8xx)
541 m8xx_init(r3
, r4
, r5
, r6
, r7
);
543 #error "No board type has been defined for identify_machine()!"
544 #endif /* CONFIG_4xx */
545 #endif /* !CONFIG_4xx && !CONFIG_8xx */
547 /* Look for mem= option on command line */
548 if (strstr(cmd_line
, "mem=")) {
550 unsigned long maxmem
= 0;
551 extern unsigned long __max_memory
;
553 for (q
= cmd_line
; (p
= strstr(q
, "mem=")) != 0; ) {
555 if (p
> cmd_line
&& p
[-1] != ' ')
557 maxmem
= simple_strtoul(q
, &q
, 0);
558 if (*q
== 'k' || *q
== 'K') {
561 } else if (*q
== 'm' || *q
== 'M') {
566 __max_memory
= maxmem
;
569 /* this is for modules since _machine can be a define -- Cort */
570 ppc_md
.ppc_machine
= _machine
;
572 if ( ppc_md
.progress
) ppc_md
.progress("id mach(): done", 0x200);
577 int parse_bootinfo(void)
579 struct bi_record
*rec
;
580 extern char __bss_start
[];
582 extern unsigned long sysmap_size
;
584 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+(1<<20)-1,(1<<20));
585 if ( rec
->tag
!= BI_FIRST
)
588 * This 0x10000 offset is a terrible hack but it will go away when
589 * we have the bootloader handle all the relocation and
592 rec
= (struct bi_record
*)_ALIGN((ulong
)__bss_start
+0x10000+(1<<20)-1,(1<<20));
593 if ( rec
->tag
!= BI_FIRST
)
596 for ( ; rec
->tag
!= BI_LAST
;
597 rec
= (struct bi_record
*)((ulong
)rec
+ rec
->size
) )
599 ulong
*data
= rec
->data
;
603 memcpy(cmd_line
, (void *)data
, rec
->size
);
606 sysmap
= (char *)((data
[0] >= (KERNELBASE
)) ? data
[0] :
607 (data
[0]+KERNELBASE
));
608 sysmap_size
= data
[1];
610 #ifdef CONFIG_BLK_DEV_INITRD
612 initrd_start
= data
[0];
613 initrd_end
= data
[0] + rec
->size
;
615 #endif /* CONFIG_BLK_DEV_INITRD */
616 #ifndef CONFIG_MACH_SPECIFIC
621 #endif /* CONFIG_MACH_SPECIFIC */
628 /* Checks "l2cr=xxxx" command-line option */
629 void ppc_setup_l2cr(char *str
, int *ints
)
631 if ( ((_get_PVR() >> 16) == 8) || ((_get_PVR() >> 16) == 12) )
633 unsigned long val
= simple_strtoul(str
, NULL
, 0);
634 printk(KERN_INFO
"l2cr set to %lx\n", val
);
640 void __init
ppc_init(void)
642 /* clear the progress line */
643 if ( ppc_md
.progress
) ppc_md
.progress(" ", 0xffff);
645 if (ppc_md
.init
!= NULL
) {
650 void __init
setup_arch(char **cmdline_p
)
652 extern int panic_timeout
;
653 extern char _etext
[], _edata
[];
655 extern void do_init_bootmem(void);
657 #ifdef CONFIG_BOOTX_TEXT
663 if (strstr(cmd_line
, "xmon"))
665 #endif /* CONFIG_XMON */
666 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: enter", 0x3eab);
667 #if defined(CONFIG_KGDB)
672 /* reboot on panic */
675 init_mm
.start_code
= PAGE_OFFSET
;
676 init_mm
.end_code
= (unsigned long) _etext
;
677 init_mm
.end_data
= (unsigned long) _edata
;
678 init_mm
.brk
= (unsigned long) klimit
;
680 /* Save unparsed command line copy for /proc/cmdline */
681 strcpy(saved_command_line
, cmd_line
);
682 *cmdline_p
= cmd_line
;
684 /* set up the bootmem stuff with available memory */
686 if ( ppc_md
.progress
) ppc_md
.progress("setup_arch: bootmem", 0x3eab);
689 if ( ppc_md
.progress
) ppc_md
.progress("arch: exit", 0x3eab);
692 void ppc_generic_ide_fix_driveid(struct hd_driveid
*id
)
695 unsigned short *stringcast
;
698 id
->config
= __le16_to_cpu(id
->config
);
699 id
->cyls
= __le16_to_cpu(id
->cyls
);
700 id
->reserved2
= __le16_to_cpu(id
->reserved2
);
701 id
->heads
= __le16_to_cpu(id
->heads
);
702 id
->track_bytes
= __le16_to_cpu(id
->track_bytes
);
703 id
->sector_bytes
= __le16_to_cpu(id
->sector_bytes
);
704 id
->sectors
= __le16_to_cpu(id
->sectors
);
705 id
->vendor0
= __le16_to_cpu(id
->vendor0
);
706 id
->vendor1
= __le16_to_cpu(id
->vendor1
);
707 id
->vendor2
= __le16_to_cpu(id
->vendor2
);
708 stringcast
= (unsigned short *)&id
->serial_no
[0];
709 for (i
=0; i
<(20/2); i
++)
710 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
711 id
->buf_type
= __le16_to_cpu(id
->buf_type
);
712 id
->buf_size
= __le16_to_cpu(id
->buf_size
);
713 id
->ecc_bytes
= __le16_to_cpu(id
->ecc_bytes
);
714 stringcast
= (unsigned short *)&id
->fw_rev
[0];
715 for (i
=0; i
<(8/2); i
++)
716 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
717 stringcast
= (unsigned short *)&id
->model
[0];
718 for (i
=0; i
<(40/2); i
++)
719 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
720 id
->dword_io
= __le16_to_cpu(id
->dword_io
);
721 id
->reserved50
= __le16_to_cpu(id
->reserved50
);
722 id
->field_valid
= __le16_to_cpu(id
->field_valid
);
723 id
->cur_cyls
= __le16_to_cpu(id
->cur_cyls
);
724 id
->cur_heads
= __le16_to_cpu(id
->cur_heads
);
725 id
->cur_sectors
= __le16_to_cpu(id
->cur_sectors
);
726 id
->cur_capacity0
= __le16_to_cpu(id
->cur_capacity0
);
727 id
->cur_capacity1
= __le16_to_cpu(id
->cur_capacity1
);
728 id
->lba_capacity
= __le32_to_cpu(id
->lba_capacity
);
729 id
->dma_1word
= __le16_to_cpu(id
->dma_1word
);
730 id
->dma_mword
= __le16_to_cpu(id
->dma_mword
);
731 id
->eide_pio_modes
= __le16_to_cpu(id
->eide_pio_modes
);
732 id
->eide_dma_min
= __le16_to_cpu(id
->eide_dma_min
);
733 id
->eide_dma_time
= __le16_to_cpu(id
->eide_dma_time
);
734 id
->eide_pio
= __le16_to_cpu(id
->eide_pio
);
735 id
->eide_pio_iordy
= __le16_to_cpu(id
->eide_pio_iordy
);
737 id
->words69_70
[i
] = __le16_to_cpu(id
->words69_70
[i
]);
739 id
->words71_74
[i
] = __le16_to_cpu(id
->words71_74
[i
]);
740 id
->queue_depth
= __le16_to_cpu(id
->queue_depth
);
742 id
->words76_79
[i
] = __le16_to_cpu(id
->words76_79
[i
]);
743 id
->major_rev_num
= __le16_to_cpu(id
->major_rev_num
);
744 id
->minor_rev_num
= __le16_to_cpu(id
->minor_rev_num
);
745 id
->command_set_1
= __le16_to_cpu(id
->command_set_1
);
746 id
->command_set_2
= __le16_to_cpu(id
->command_set_2
);
747 id
->cfsse
= __le16_to_cpu(id
->cfsse
);
748 id
->cfs_enable_1
= __le16_to_cpu(id
->cfs_enable_1
);
749 id
->cfs_enable_2
= __le16_to_cpu(id
->cfs_enable_2
);
750 id
->csf_default
= __le16_to_cpu(id
->csf_default
);
751 id
->dma_ultra
= __le16_to_cpu(id
->dma_ultra
);
752 id
->word89
= __le16_to_cpu(id
->word89
);
753 id
->word90
= __le16_to_cpu(id
->word90
);
754 id
->CurAPMvalues
= __le16_to_cpu(id
->CurAPMvalues
);
755 id
->word92
= __le16_to_cpu(id
->word92
);
756 id
->hw_config
= __le16_to_cpu(id
->hw_config
);
758 id
->words94_125
[i
] = __le16_to_cpu(id
->words94_125
[i
]);
759 id
->last_lun
= __le16_to_cpu(id
->last_lun
);
760 id
->word127
= __le16_to_cpu(id
->word127
);
761 id
->dlf
= __le16_to_cpu(id
->dlf
);
762 id
->csfo
= __le16_to_cpu(id
->csfo
);
764 id
->words130_159
[i
] = __le16_to_cpu(id
->words130_159
[i
]);
766 id
->words160_255
[i
] = __le16_to_cpu(id
->words160_255
[i
]);