]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/powerpc/kernel/setup_64.c
powerpc: create kernel/setup.h
[karo-tx-linux.git] / arch / powerpc / kernel / setup_64.c
1 /*
2  * 
3  * Common boot and setup code.
4  *
5  * Copyright (C) 2001 PPC64 Team, IBM Corp
6  *
7  *      This program is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU General Public License
9  *      as published by the Free Software Foundation; either version
10  *      2 of the License, or (at your option) any later version.
11  */
12
13 #undef DEBUG
14
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/reboot.h>
22 #include <linux/delay.h>
23 #include <linux/initrd.h>
24 #include <linux/ide.h>
25 #include <linux/seq_file.h>
26 #include <linux/ioport.h>
27 #include <linux/console.h>
28 #include <linux/utsname.h>
29 #include <linux/tty.h>
30 #include <linux/root_dev.h>
31 #include <linux/notifier.h>
32 #include <linux/cpu.h>
33 #include <linux/unistd.h>
34 #include <linux/serial.h>
35 #include <linux/serial_8250.h>
36 #include <asm/io.h>
37 #include <asm/prom.h>
38 #include <asm/processor.h>
39 #include <asm/pgtable.h>
40 #include <asm/smp.h>
41 #include <asm/elf.h>
42 #include <asm/machdep.h>
43 #include <asm/paca.h>
44 #include <asm/time.h>
45 #include <asm/cputable.h>
46 #include <asm/sections.h>
47 #include <asm/btext.h>
48 #include <asm/nvram.h>
49 #include <asm/setup.h>
50 #include <asm/system.h>
51 #include <asm/rtas.h>
52 #include <asm/iommu.h>
53 #include <asm/serial.h>
54 #include <asm/cache.h>
55 #include <asm/page.h>
56 #include <asm/mmu.h>
57 #include <asm/lmb.h>
58 #include <asm/iseries/it_lp_naca.h>
59 #include <asm/firmware.h>
60 #include <asm/systemcfg.h>
61 #include <asm/xmon.h>
62 #include <asm/udbg.h>
63
64 #include "setup.h"
65
66 #ifdef DEBUG
67 #define DBG(fmt...) udbg_printf(fmt)
68 #else
69 #define DBG(fmt...)
70 #endif
71
72 /*
73  * Here are some early debugging facilities. You can enable one
74  * but your kernel will not boot on anything else if you do so
75  */
76
77 /* This one is for use on LPAR machines that support an HVC console
78  * on vterm 0
79  */
80 extern void udbg_init_debug_lpar(void);
81 /* This one is for use on Apple G5 machines
82  */
83 extern void udbg_init_pmac_realmode(void);
84 /* That's RTAS panel debug */
85 extern void call_rtas_display_status_delay(unsigned char c);
86 /* Here's maple real mode debug */
87 extern void udbg_init_maple_realmode(void);
88
89 #define EARLY_DEBUG_INIT() do {} while(0)
90
91 #if 0
92 #define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
93 #define EARLY_DEBUG_INIT() udbg_init_maple_realmode()
94 #define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
95 #define EARLY_DEBUG_INIT()                                              \
96         do { udbg_putc = call_rtas_display_status_delay; } while(0)
97 #endif
98
99 /* extern void *stab; */
100 extern unsigned long klimit;
101
102 extern void mm_init_ppc64(void);
103 extern void stab_initialize(unsigned long stab);
104 extern void htab_initialize(void);
105 extern void early_init_devtree(void *flat_dt);
106 extern void unflatten_device_tree(void);
107
108 int have_of = 1;
109 int boot_cpuid = 0;
110 int boot_cpuid_phys = 0;
111 dev_t boot_dev;
112 u64 ppc64_pft_size;
113
114 struct ppc64_caches ppc64_caches;
115 EXPORT_SYMBOL_GPL(ppc64_caches);
116
117 /*
118  * These are used in binfmt_elf.c to put aux entries on the stack
119  * for each elf executable being started.
120  */
121 int dcache_bsize;
122 int icache_bsize;
123 int ucache_bsize;
124
125 /* The main machine-dep calls structure
126  */
127 struct machdep_calls ppc_md;
128 EXPORT_SYMBOL(ppc_md);
129
130 #ifdef CONFIG_MAGIC_SYSRQ
131 unsigned long SYSRQ_KEY;
132 #endif /* CONFIG_MAGIC_SYSRQ */
133
134
135 static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
136 static struct notifier_block ppc64_panic_block = {
137         .notifier_call = ppc64_panic_event,
138         .priority = INT_MIN /* may not return; must be done last */
139 };
140
141 #ifdef CONFIG_SMP
142
143 static int smt_enabled_cmdline;
144
145 /* Look for ibm,smt-enabled OF option */
146 static void check_smt_enabled(void)
147 {
148         struct device_node *dn;
149         char *smt_option;
150
151         /* Allow the command line to overrule the OF option */
152         if (smt_enabled_cmdline)
153                 return;
154
155         dn = of_find_node_by_path("/options");
156
157         if (dn) {
158                 smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
159
160                 if (smt_option) {
161                         if (!strcmp(smt_option, "on"))
162                                 smt_enabled_at_boot = 1;
163                         else if (!strcmp(smt_option, "off"))
164                                 smt_enabled_at_boot = 0;
165                 }
166         }
167 }
168
169 /* Look for smt-enabled= cmdline option */
170 static int __init early_smt_enabled(char *p)
171 {
172         smt_enabled_cmdline = 1;
173
174         if (!p)
175                 return 0;
176
177         if (!strcmp(p, "on") || !strcmp(p, "1"))
178                 smt_enabled_at_boot = 1;
179         else if (!strcmp(p, "off") || !strcmp(p, "0"))
180                 smt_enabled_at_boot = 0;
181
182         return 0;
183 }
184 early_param("smt-enabled", early_smt_enabled);
185
186 #else
187 #define check_smt_enabled()
188 #endif /* CONFIG_SMP */
189
190 extern struct machdep_calls pSeries_md;
191 extern struct machdep_calls pmac_md;
192 extern struct machdep_calls maple_md;
193 extern struct machdep_calls cell_md;
194 extern struct machdep_calls iseries_md;
195
196 /* Ultimately, stuff them in an elf section like initcalls... */
197 static struct machdep_calls __initdata *machines[] = {
198 #ifdef CONFIG_PPC_PSERIES
199         &pSeries_md,
200 #endif /* CONFIG_PPC_PSERIES */
201 #ifdef CONFIG_PPC_PMAC
202         &pmac_md,
203 #endif /* CONFIG_PPC_PMAC */
204 #ifdef CONFIG_PPC_MAPLE
205         &maple_md,
206 #endif /* CONFIG_PPC_MAPLE */
207 #ifdef CONFIG_PPC_CELL
208         &cell_md,
209 #endif
210 #ifdef CONFIG_PPC_ISERIES
211         &iseries_md,
212 #endif
213         NULL
214 };
215
216 /*
217  * Early initialization entry point. This is called by head.S
218  * with MMU translation disabled. We rely on the "feature" of
219  * the CPU that ignores the top 2 bits of the address in real
220  * mode so we can access kernel globals normally provided we
221  * only toy with things in the RMO region. From here, we do
222  * some early parsing of the device-tree to setup out LMB
223  * data structures, and allocate & initialize the hash table
224  * and segment tables so we can start running with translation
225  * enabled.
226  *
227  * It is this function which will call the probe() callback of
228  * the various platform types and copy the matching one to the
229  * global ppc_md structure. Your platform can eventually do
230  * some very early initializations from the probe() routine, but
231  * this is not recommended, be very careful as, for example, the
232  * device-tree is not accessible via normal means at this point.
233  */
234
235 void __init early_setup(unsigned long dt_ptr)
236 {
237         struct paca_struct *lpaca = get_paca();
238         static struct machdep_calls **mach;
239
240         /*
241          * Enable early debugging if any specified (see top of
242          * this file)
243          */
244         EARLY_DEBUG_INIT();
245
246         DBG(" -> early_setup()\n");
247
248         /*
249          * Do early initializations using the flattened device
250          * tree, like retreiving the physical memory map or
251          * calculating/retreiving the hash table size
252          */
253         early_init_devtree(__va(dt_ptr));
254
255         /*
256          * Iterate all ppc_md structures until we find the proper
257          * one for the current machine type
258          */
259         DBG("Probing machine type for platform %x...\n",
260             systemcfg->platform);
261
262         for (mach = machines; *mach; mach++) {
263                 if ((*mach)->probe(systemcfg->platform))
264                         break;
265         }
266         /* What can we do if we didn't find ? */
267         if (*mach == NULL) {
268                 DBG("No suitable machine found !\n");
269                 for (;;);
270         }
271         ppc_md = **mach;
272
273         DBG("Found, Initializing memory management...\n");
274
275         /*
276          * Initialize the MMU Hash table and create the linear mapping
277          * of memory. Has to be done before stab/slb initialization as
278          * this is currently where the page size encoding is obtained
279          */
280         htab_initialize();
281
282         /*
283          * Initialize stab / SLB management except on iSeries
284          */
285         if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
286                 if (cpu_has_feature(CPU_FTR_SLB))
287                         slb_initialize();
288                 else
289                         stab_initialize(lpaca->stab_real);
290         }
291
292         DBG(" <- early_setup()\n");
293 }
294
295
296 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
297 void smp_release_cpus(void)
298 {
299         extern unsigned long __secondary_hold_spinloop;
300
301         DBG(" -> smp_release_cpus()\n");
302
303         /* All secondary cpus are spinning on a common spinloop, release them
304          * all now so they can start to spin on their individual paca
305          * spinloops. For non SMP kernels, the secondary cpus never get out
306          * of the common spinloop.
307          * This is useless but harmless on iSeries, secondaries are already
308          * waiting on their paca spinloops. */
309
310         __secondary_hold_spinloop = 1;
311         mb();
312
313         DBG(" <- smp_release_cpus()\n");
314 }
315 #else
316 #define smp_release_cpus()
317 #endif /* CONFIG_SMP || CONFIG_KEXEC */
318
319 /*
320  * Initialize some remaining members of the ppc64_caches and systemcfg structures
321  * (at least until we get rid of them completely). This is mostly some
322  * cache informations about the CPU that will be used by cache flush
323  * routines and/or provided to userland
324  */
325 static void __init initialize_cache_info(void)
326 {
327         struct device_node *np;
328         unsigned long num_cpus = 0;
329
330         DBG(" -> initialize_cache_info()\n");
331
332         for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
333                 num_cpus += 1;
334
335                 /* We're assuming *all* of the CPUs have the same
336                  * d-cache and i-cache sizes... -Peter
337                  */
338
339                 if ( num_cpus == 1 ) {
340                         u32 *sizep, *lsizep;
341                         u32 size, lsize;
342                         const char *dc, *ic;
343
344                         /* Then read cache informations */
345                         if (systemcfg->platform == PLATFORM_POWERMAC) {
346                                 dc = "d-cache-block-size";
347                                 ic = "i-cache-block-size";
348                         } else {
349                                 dc = "d-cache-line-size";
350                                 ic = "i-cache-line-size";
351                         }
352
353                         size = 0;
354                         lsize = cur_cpu_spec->dcache_bsize;
355                         sizep = (u32 *)get_property(np, "d-cache-size", NULL);
356                         if (sizep != NULL)
357                                 size = *sizep;
358                         lsizep = (u32 *) get_property(np, dc, NULL);
359                         if (lsizep != NULL)
360                                 lsize = *lsizep;
361                         if (sizep == 0 || lsizep == 0)
362                                 DBG("Argh, can't find dcache properties ! "
363                                     "sizep: %p, lsizep: %p\n", sizep, lsizep);
364
365                         systemcfg->dcache_size = ppc64_caches.dsize = size;
366                         systemcfg->dcache_line_size =
367                                 ppc64_caches.dline_size = lsize;
368                         ppc64_caches.log_dline_size = __ilog2(lsize);
369                         ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
370
371                         size = 0;
372                         lsize = cur_cpu_spec->icache_bsize;
373                         sizep = (u32 *)get_property(np, "i-cache-size", NULL);
374                         if (sizep != NULL)
375                                 size = *sizep;
376                         lsizep = (u32 *)get_property(np, ic, NULL);
377                         if (lsizep != NULL)
378                                 lsize = *lsizep;
379                         if (sizep == 0 || lsizep == 0)
380                                 DBG("Argh, can't find icache properties ! "
381                                     "sizep: %p, lsizep: %p\n", sizep, lsizep);
382
383                         systemcfg->icache_size = ppc64_caches.isize = size;
384                         systemcfg->icache_line_size =
385                                 ppc64_caches.iline_size = lsize;
386                         ppc64_caches.log_iline_size = __ilog2(lsize);
387                         ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
388                 }
389         }
390
391         /* Add an eye catcher and the systemcfg layout version number */
392         strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
393         systemcfg->version.major = SYSTEMCFG_MAJOR;
394         systemcfg->version.minor = SYSTEMCFG_MINOR;
395         systemcfg->processor = mfspr(SPRN_PVR);
396
397         DBG(" <- initialize_cache_info()\n");
398 }
399
400
401 /*
402  * Do some initial setup of the system.  The parameters are those which 
403  * were passed in from the bootloader.
404  */
405 void __init setup_system(void)
406 {
407         DBG(" -> setup_system()\n");
408
409         /*
410          * Unflatten the device-tree passed by prom_init or kexec
411          */
412         unflatten_device_tree();
413
414         /*
415          * Fill the ppc64_caches & systemcfg structures with informations
416          * retreived from the device-tree. Need to be called before
417          * finish_device_tree() since the later requires some of the
418          * informations filled up here to properly parse the interrupt
419          * tree.
420          * It also sets up the cache line sizes which allows to call
421          * routines like flush_icache_range (used by the hash init
422          * later on).
423          */
424         initialize_cache_info();
425
426 #ifdef CONFIG_PPC_RTAS
427         /*
428          * Initialize RTAS if available
429          */
430         rtas_initialize();
431 #endif /* CONFIG_PPC_RTAS */
432
433         /*
434          * Check if we have an initrd provided via the device-tree
435          */
436         check_for_initrd();
437
438         /*
439          * Do some platform specific early initializations, that includes
440          * setting up the hash table pointers. It also sets up some interrupt-mapping
441          * related options that will be used by finish_device_tree()
442          */
443         ppc_md.init_early();
444
445         /*
446          * "Finish" the device-tree, that is do the actual parsing of
447          * some of the properties like the interrupt map
448          */
449         finish_device_tree();
450
451 #ifdef CONFIG_BOOTX_TEXT
452         init_boot_display();
453 #endif
454
455         /*
456          * Initialize xmon
457          */
458 #ifdef CONFIG_XMON_DEFAULT
459         xmon_init(1);
460 #endif
461         /*
462          * Register early console
463          */
464         register_early_udbg_console();
465
466         /* Save unparsed command line copy for /proc/cmdline */
467         strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
468
469         parse_early_param();
470
471         check_smt_enabled();
472         smp_setup_cpu_maps();
473
474         /* Release secondary cpus out of their spinloops at 0x60 now that
475          * we can map physical -> logical CPU ids
476          */
477         smp_release_cpus();
478
479         printk("Starting Linux PPC64 %s\n", system_utsname.version);
480
481         printk("-----------------------------------------------------\n");
482         printk("ppc64_pft_size                = 0x%lx\n", ppc64_pft_size);
483         printk("ppc64_interrupt_controller    = 0x%ld\n", ppc64_interrupt_controller);
484         printk("systemcfg                     = 0x%p\n", systemcfg);
485         printk("systemcfg->platform           = 0x%x\n", systemcfg->platform);
486         printk("systemcfg->processorCount     = 0x%lx\n", systemcfg->processorCount);
487         printk("systemcfg->physicalMemorySize = 0x%lx\n", systemcfg->physicalMemorySize);
488         printk("ppc64_caches.dcache_line_size = 0x%x\n",
489                         ppc64_caches.dline_size);
490         printk("ppc64_caches.icache_line_size = 0x%x\n",
491                         ppc64_caches.iline_size);
492         printk("htab_address                  = 0x%p\n", htab_address);
493         printk("htab_hash_mask                = 0x%lx\n", htab_hash_mask);
494         printk("-----------------------------------------------------\n");
495
496         mm_init_ppc64();
497
498         DBG(" <- setup_system()\n");
499 }
500
501 static int ppc64_panic_event(struct notifier_block *this,
502                              unsigned long event, void *ptr)
503 {
504         ppc_md.panic((char *)ptr);  /* May not return */
505         return NOTIFY_DONE;
506 }
507
508 #ifdef CONFIG_IRQSTACKS
509 static void __init irqstack_early_init(void)
510 {
511         unsigned int i;
512
513         /*
514          * interrupt stacks must be under 256MB, we cannot afford to take
515          * SLB misses on them.
516          */
517         for_each_cpu(i) {
518                 softirq_ctx[i] = (struct thread_info *)
519                         __va(lmb_alloc_base(THREAD_SIZE,
520                                             THREAD_SIZE, 0x10000000));
521                 hardirq_ctx[i] = (struct thread_info *)
522                         __va(lmb_alloc_base(THREAD_SIZE,
523                                             THREAD_SIZE, 0x10000000));
524         }
525 }
526 #else
527 #define irqstack_early_init()
528 #endif
529
530 /*
531  * Stack space used when we detect a bad kernel stack pointer, and
532  * early in SMP boots before relocation is enabled.
533  */
534 static void __init emergency_stack_init(void)
535 {
536         unsigned long limit;
537         unsigned int i;
538
539         /*
540          * Emergency stacks must be under 256MB, we cannot afford to take
541          * SLB misses on them. The ABI also requires them to be 128-byte
542          * aligned.
543          *
544          * Since we use these as temporary stacks during secondary CPU
545          * bringup, we need to get at them in real mode. This means they
546          * must also be within the RMO region.
547          */
548         limit = min(0x10000000UL, lmb.rmo_size);
549
550         for_each_cpu(i)
551                 paca[i].emergency_sp =
552                 __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE;
553 }
554
555 /*
556  * Called from setup_arch to initialize the bitmap of available
557  * syscalls in the systemcfg page
558  */
559 void __init setup_syscall_map(void)
560 {
561         unsigned int i, count64 = 0, count32 = 0;
562         extern unsigned long *sys_call_table;
563         extern unsigned long sys_ni_syscall;
564
565
566         for (i = 0; i < __NR_syscalls; i++) {
567                 if (sys_call_table[i*2] != sys_ni_syscall) {
568                         count64++;
569                         systemcfg->syscall_map_64[i >> 5] |=
570                                 0x80000000UL >> (i & 0x1f);
571                 }
572                 if (sys_call_table[i*2+1] != sys_ni_syscall) {
573                         count32++;
574                         systemcfg->syscall_map_32[i >> 5] |=
575                                 0x80000000UL >> (i & 0x1f);
576                 }
577         }
578         printk(KERN_INFO "Syscall map setup, %d 32-bit and %d 64-bit syscalls\n",
579                count32, count64);
580 }
581
582 /*
583  * Called into from start_kernel, after lock_kernel has been called.
584  * Initializes bootmem, which is unsed to manage page allocation until
585  * mem_init is called.
586  */
587 void __init setup_arch(char **cmdline_p)
588 {
589         extern void do_init_bootmem(void);
590
591         ppc64_boot_msg(0x12, "Setup Arch");
592
593         *cmdline_p = cmd_line;
594
595         /*
596          * Set cache line size based on type of cpu as a default.
597          * Systems with OF can look in the properties on the cpu node(s)
598          * for a possibly more accurate value.
599          */
600         dcache_bsize = ppc64_caches.dline_size;
601         icache_bsize = ppc64_caches.iline_size;
602
603         /* reboot on panic */
604         panic_timeout = 180;
605
606         if (ppc_md.panic)
607                 notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
608
609         init_mm.start_code = PAGE_OFFSET;
610         init_mm.end_code = (unsigned long) _etext;
611         init_mm.end_data = (unsigned long) _edata;
612         init_mm.brk = klimit;
613         
614         irqstack_early_init();
615         emergency_stack_init();
616
617         stabs_alloc();
618
619         /* set up the bootmem stuff with available memory */
620         do_init_bootmem();
621         sparse_init();
622
623         /* initialize the syscall map in systemcfg */
624         setup_syscall_map();
625
626 #ifdef CONFIG_DUMMY_CONSOLE
627         conswitchp = &dummy_con;
628 #endif
629
630         ppc_md.setup_arch();
631
632         /* Use the default idle loop if the platform hasn't provided one. */
633         if (NULL == ppc_md.idle_loop) {
634                 ppc_md.idle_loop = default_idle;
635                 printk(KERN_INFO "Using default idle loop\n");
636         }
637
638         paging_init();
639         ppc64_boot_msg(0x15, "Setup Done");
640 }
641
642
643 /* ToDo: do something useful if ppc_md is not yet setup. */
644 #define PPC64_LINUX_FUNCTION 0x0f000000
645 #define PPC64_IPL_MESSAGE 0xc0000000
646 #define PPC64_TERM_MESSAGE 0xb0000000
647
648 static void ppc64_do_msg(unsigned int src, const char *msg)
649 {
650         if (ppc_md.progress) {
651                 char buf[128];
652
653                 sprintf(buf, "%08X\n", src);
654                 ppc_md.progress(buf, 0);
655                 snprintf(buf, 128, "%s", msg);
656                 ppc_md.progress(buf, 0);
657         }
658 }
659
660 /* Print a boot progress message. */
661 void ppc64_boot_msg(unsigned int src, const char *msg)
662 {
663         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
664         printk("[boot]%04x %s\n", src, msg);
665 }
666
667 /* Print a termination message (print only -- does not stop the kernel) */
668 void ppc64_terminate_msg(unsigned int src, const char *msg)
669 {
670         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
671         printk("[terminate]%04x %s\n", src, msg);
672 }
673
674 #ifndef CONFIG_PPC_ISERIES
675 /*
676  * This function can be used by platforms to "find" legacy serial ports.
677  * It works for "serial" nodes under an "isa" node, and will try to
678  * respect the "ibm,aix-loc" property if any. It works with up to 8
679  * ports.
680  */
681
682 #define MAX_LEGACY_SERIAL_PORTS 8
683 static struct plat_serial8250_port serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
684 static unsigned int old_serial_count;
685
686 void __init generic_find_legacy_serial_ports(u64 *physport,
687                 unsigned int *default_speed)
688 {
689         struct device_node *np;
690         u32 *sizeprop;
691
692         struct isa_reg_property {
693                 u32 space;
694                 u32 address;
695                 u32 size;
696         };
697         struct pci_reg_property {
698                 struct pci_address addr;
699                 u32 size_hi;
700                 u32 size_lo;
701         };                                                                        
702
703         DBG(" -> generic_find_legacy_serial_port()\n");
704
705         *physport = 0;
706         if (default_speed)
707                 *default_speed = 0;
708
709         np = of_find_node_by_path("/");
710         if (!np)
711                 return;
712
713         /* First fill our array */
714         for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
715                 struct device_node *isa, *pci;
716                 struct isa_reg_property *reg;
717                 unsigned long phys_size, addr_size, io_base;
718                 u32 *rangesp;
719                 u32 *interrupts, *clk, *spd;
720                 char *typep;
721                 int index, rlen, rentsize;
722
723                 /* Ok, first check if it's under an "isa" parent */
724                 isa = of_get_parent(np);
725                 if (!isa || strcmp(isa->name, "isa")) {
726                         DBG("%s: no isa parent found\n", np->full_name);
727                         continue;
728                 }
729                 
730                 /* Now look for an "ibm,aix-loc" property that gives us ordering
731                  * if any...
732                  */
733                 typep = (char *)get_property(np, "ibm,aix-loc", NULL);
734
735                 /* Get the ISA port number */
736                 reg = (struct isa_reg_property *)get_property(np, "reg", NULL); 
737                 if (reg == NULL)
738                         goto next_port;
739                 /* We assume the interrupt number isn't translated ... */
740                 interrupts = (u32 *)get_property(np, "interrupts", NULL);
741                 /* get clock freq. if present */
742                 clk = (u32 *)get_property(np, "clock-frequency", NULL);
743                 /* get default speed if present */
744                 spd = (u32 *)get_property(np, "current-speed", NULL);
745                 /* Default to locate at end of array */
746                 index = old_serial_count; /* end of the array by default */
747
748                 /* If we have a location index, then use it */
749                 if (typep && *typep == 'S') {
750                         index = simple_strtol(typep+1, NULL, 0) - 1;
751                         /* if index is out of range, use end of array instead */
752                         if (index >= MAX_LEGACY_SERIAL_PORTS)
753                                 index = old_serial_count;
754                         /* if our index is still out of range, that mean that
755                          * array is full, we could scan for a free slot but that
756                          * make little sense to bother, just skip the port
757                          */
758                         if (index >= MAX_LEGACY_SERIAL_PORTS)
759                                 goto next_port;
760                         if (index >= old_serial_count)
761                                 old_serial_count = index + 1;
762                         /* Check if there is a port who already claimed our slot */
763                         if (serial_ports[index].iobase != 0) {
764                                 /* if we still have some room, move it, else override */
765                                 if (old_serial_count < MAX_LEGACY_SERIAL_PORTS) {
766                                         DBG("Moved legacy port %d -> %d\n", index,
767                                             old_serial_count);
768                                         serial_ports[old_serial_count++] =
769                                                 serial_ports[index];
770                                 } else {
771                                         DBG("Replacing legacy port %d\n", index);
772                                 }
773                         }
774                 }
775                 if (index >= MAX_LEGACY_SERIAL_PORTS)
776                         goto next_port;
777                 if (index >= old_serial_count)
778                         old_serial_count = index + 1;
779
780                 /* Now fill the entry */
781                 memset(&serial_ports[index], 0, sizeof(struct plat_serial8250_port));
782                 serial_ports[index].uartclk = clk ? *clk : BASE_BAUD * 16;
783                 serial_ports[index].iobase = reg->address;
784                 serial_ports[index].irq = interrupts ? interrupts[0] : 0;
785                 serial_ports[index].flags = ASYNC_BOOT_AUTOCONF;
786
787                 DBG("Added legacy port, index: %d, port: %x, irq: %d, clk: %d\n",
788                     index,
789                     serial_ports[index].iobase,
790                     serial_ports[index].irq,
791                     serial_ports[index].uartclk);
792
793                 /* Get phys address of IO reg for port 1 */
794                 if (index != 0)
795                         goto next_port;
796
797                 pci = of_get_parent(isa);
798                 if (!pci) {
799                         DBG("%s: no pci parent found\n", np->full_name);
800                         goto next_port;
801                 }
802
803                 rangesp = (u32 *)get_property(pci, "ranges", &rlen);
804                 if (rangesp == NULL) {
805                         of_node_put(pci);
806                         goto next_port;
807                 }
808                 rlen /= 4;
809
810                 /* we need the #size-cells of the PCI bridge node itself */
811                 phys_size = 1;
812                 sizeprop = (u32 *)get_property(pci, "#size-cells", NULL);
813                 if (sizeprop != NULL)
814                         phys_size = *sizeprop;
815                 /* we need the parent #addr-cells */
816                 addr_size = prom_n_addr_cells(pci);
817                 rentsize = 3 + addr_size + phys_size;
818                 io_base = 0;
819                 for (;rlen >= rentsize; rlen -= rentsize,rangesp += rentsize) {
820                         if (((rangesp[0] >> 24) & 0x3) != 1)
821                                 continue; /* not IO space */
822                         io_base = rangesp[3];
823                         if (addr_size == 2)
824                                 io_base = (io_base << 32) | rangesp[4];
825                 }
826                 if (io_base != 0) {
827                         *physport = io_base + reg->address;
828                         if (default_speed && spd)
829                                 *default_speed = *spd;
830                 }
831                 of_node_put(pci);
832         next_port:
833                 of_node_put(isa);
834         }
835
836         DBG(" <- generic_find_legacy_serial_port()\n");
837 }
838
839 static struct platform_device serial_device = {
840         .name   = "serial8250",
841         .id     = PLAT8250_DEV_PLATFORM,
842         .dev    = {
843                 .platform_data = serial_ports,
844         },
845 };
846
847 static int __init serial_dev_init(void)
848 {
849         return platform_device_register(&serial_device);
850 }
851 arch_initcall(serial_dev_init);
852
853 #endif /* CONFIG_PPC_ISERIES */
854
855 int check_legacy_ioport(unsigned long base_port)
856 {
857         if (ppc_md.check_legacy_ioport == NULL)
858                 return 0;
859         return ppc_md.check_legacy_ioport(base_port);
860 }
861 EXPORT_SYMBOL(check_legacy_ioport);
862
863 void cpu_die(void)
864 {
865         if (ppc_md.cpu_die)
866                 ppc_md.cpu_die();
867 }