port enough sendpoint support for DSM-G600 from D-Link 2.4.21-pre4
[linux-2.4.git] / arch / ppc / platforms / pmac_setup.c
1 /*
2  *  arch/ppc/platforms/setup.c
3  *
4  *  PowerPC version
5  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6  *
7  *  Adapted for Power Macintosh by Paul Mackerras
8  *    Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
9  *
10  *  Derived from "arch/alpha/kernel/setup.c"
11  *    Copyright (C) 1995 Linus Torvalds
12  *
13  *  This program is free software; you can redistribute it and/or
14  *  modify it under the terms of the GNU General Public License
15  *  as published by the Free Software Foundation; either version
16  *  2 of the License, or (at your option) any later version.
17  *
18  */
19
20 /*
21  * bootup setup stuff..
22  */
23
24 #include <linux/config.h>
25 #include <linux/init.h>
26 #include <linux/errno.h>
27 #include <linux/sched.h>
28 #include <linux/kernel.h>
29 #include <linux/mm.h>
30 #include <linux/stddef.h>
31 #include <linux/unistd.h>
32 #include <linux/ptrace.h>
33 #include <linux/slab.h>
34 #include <linux/user.h>
35 #include <linux/a.out.h>
36 #include <linux/tty.h>
37 #include <linux/string.h>
38 #include <linux/delay.h>
39 #include <linux/ioport.h>
40 #include <linux/major.h>
41 #include <linux/blk.h>
42 #include <linux/vt_kern.h>
43 #include <linux/console.h>
44 #include <linux/ide.h>
45 #include <linux/pci.h>
46 #include <linux/adb.h>
47 #include <linux/cuda.h>
48 #include <linux/pmu.h>
49 #include <linux/irq.h>
50 #include <linux/seq_file.h>
51 #include <linux/blkdev.h>
52 #include <linux/genhd.h>
53
54 #include <asm/processor.h>
55 #include <asm/sections.h>
56 #include <asm/prom.h>
57 #include <asm/system.h>
58 #include <asm/pgtable.h>
59 #include <asm/bitops.h>
60 #include <asm/io.h>
61 #include <asm/pci-bridge.h>
62 #include <asm/ohare.h>
63 #include <asm/mediabay.h>
64 #include <asm/machdep.h>
65 #include <asm/keyboard.h>
66 #include <asm/dma.h>
67 #include <asm/bootx.h>
68 #include <asm/cputable.h>
69 #include <asm/btext.h>
70 #include <asm/pmac_feature.h>
71 #include <asm/time.h>
72
73 #include "pmac_pic.h"
74 #include "mem_pieces.h"
75 #include "scsi.h" /* sd_find_target */
76 #include "sd.h"
77 #include "mac.h"
78
79 extern long pmac_time_init(void);
80 extern unsigned long pmac_get_rtc_time(void);
81 extern int pmac_set_rtc_time(unsigned long nowtime);
82 extern void pmac_read_rtc_time(void);
83 extern void pmac_calibrate_decr(void);
84 extern void pmac_pcibios_fixup(void);
85 extern void pmac_find_bridges(void);
86 extern ide_ioreg_t pmac_ide_get_base(int index);
87 extern void pmac_ide_init_hwif_ports(hw_regs_t *hw,
88         ide_ioreg_t data_port, ide_ioreg_t ctrl_port, int *irq);
89
90 extern int mackbd_setkeycode(unsigned int scancode, unsigned int keycode);
91 extern int mackbd_getkeycode(unsigned int scancode);
92 extern int mackbd_translate(unsigned char keycode, unsigned char *keycodep,
93                      char raw_mode);
94 extern char mackbd_unexpected_up(unsigned char keycode);
95 extern void mackbd_leds(unsigned char leds);
96 extern void __init mackbd_init_hw(void);
97 extern int mac_hid_kbd_translate(unsigned char scancode, unsigned char *keycode,
98                                  char raw_mode);
99 extern char mac_hid_kbd_unexpected_up(unsigned char keycode);
100 extern void mac_hid_init_hw(void);
101 extern unsigned char mac_hid_kbd_sysrq_xlate[];
102 extern unsigned char pckbd_sysrq_xlate[];
103 extern unsigned char mackbd_sysrq_xlate[];
104 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
105 extern int pckbd_getkeycode(unsigned int scancode);
106 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
107                            char raw_mode);
108 extern char pckbd_unexpected_up(unsigned char keycode);
109 extern int keyboard_sends_linux_keycodes;
110 extern void pmac_nvram_update(void);
111
112 extern int pmac_pci_enable_device_hook(struct pci_dev *dev, int initial);
113 extern void pmac_pcibios_after_init(void);
114
115 struct device_node *memory_node;
116
117 unsigned char drive_info;
118
119 int ppc_override_l2cr = 0;
120 int ppc_override_l2cr_value;
121 int has_l2cache = 0;
122
123 static int current_root_goodness = -1;
124
125 extern char saved_command_line[];
126
127 extern int pmac_newworld;
128
129 #define DEFAULT_ROOT_DEVICE 0x0801      /* sda1 - slightly silly choice */
130
131 extern void zs_kgdb_hook(int tty_num);
132 static void ohare_init(void);
133 #ifdef CONFIG_BOOTX_TEXT
134 void pmac_progress(char *s, unsigned short hex);
135 #endif
136
137 sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
138
139 #ifdef CONFIG_SMP
140 extern struct smp_ops_t psurge_smp_ops;
141 extern struct smp_ops_t core99_smp_ops;
142 #endif /* CONFIG_SMP */
143
144 /*
145  * Assume here that all clock rates are the same in a
146  * smp system.  -- Cort
147  */
148 int __openfirmware
149 of_show_percpuinfo(struct seq_file *m, int i)
150 {
151         struct device_node *cpu_node;
152         int *fp, s;
153
154         cpu_node = find_type_devices("cpu");
155         if (!cpu_node)
156                 return 0;
157         for (s = 0; s < i && cpu_node->next; s++)
158                 cpu_node = cpu_node->next;
159         fp = (int *) get_property(cpu_node, "clock-frequency", NULL);
160         if (fp)
161                 seq_printf(m, "clock\t\t: %dMHz\n", *fp / 1000000);
162         return 0;
163 }
164
165 int __pmac
166 pmac_show_cpuinfo(struct seq_file *m)
167 {
168         struct device_node *np;
169         char *pp;
170         int plen;
171         int mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
172                 NULL, PMAC_MB_INFO_MODEL, 0);
173         unsigned int mbflags = (unsigned int)pmac_call_feature(PMAC_FTR_GET_MB_INFO,
174                 NULL, PMAC_MB_INFO_FLAGS, 0);
175         char* mbname;
176
177         if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME, (int)&mbname) != 0)
178                 mbname = "Unknown";
179
180         /* find motherboard type */
181         seq_printf(m, "machine\t\t: ");
182         np = find_devices("device-tree");
183         if (np != NULL) {
184                 pp = (char *) get_property(np, "model", NULL);
185                 if (pp != NULL)
186                         seq_printf(m, "%s\n", pp);
187                 else
188                         seq_printf(m, "PowerMac\n");
189                 pp = (char *) get_property(np, "compatible", &plen);
190                 if (pp != NULL) {
191                         seq_printf(m, "motherboard\t:");
192                         while (plen > 0) {
193                                 int l = strlen(pp) + 1;
194                                 seq_printf(m, " %s", pp);
195                                 plen -= l;
196                                 pp += l;
197                         }
198                         seq_printf(m, "\n");
199                 }
200         } else
201                 seq_printf(m, "PowerMac\n");
202
203         /* print parsed model */
204         seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
205         seq_printf(m, "pmac flags\t: %08x\n", mbflags);
206
207         /* find l2 cache info */
208         np = find_devices("l2-cache");
209         if (np == 0)
210                 np = find_type_devices("cache");
211         if (np != 0) {
212                 unsigned int *ic = (unsigned int *)
213                         get_property(np, "i-cache-size", NULL);
214                 unsigned int *dc = (unsigned int *)
215                         get_property(np, "d-cache-size", NULL);
216                 seq_printf(m, "L2 cache\t:");
217                 has_l2cache = 1;
218                 if (get_property(np, "cache-unified", NULL) != 0 && dc) {
219                         seq_printf(m, " %dK unified", *dc / 1024);
220                 } else {
221                         if (ic)
222                                 seq_printf(m, " %dK instruction", *ic / 1024);
223                         if (dc)
224                                 seq_printf(m, "%s %dK data",
225                                            (ic? " +": ""), *dc / 1024);
226                 }
227                 pp = get_property(np, "ram-type", NULL);
228                 if (pp)
229                         seq_printf(m, " %s", pp);
230                 seq_printf(m, "\n");
231         }
232
233         /* find ram info */
234         np = find_devices("memory");
235         if (np != 0) {
236                 int n;
237                 struct reg_property *reg = (struct reg_property *)
238                         get_property(np, "reg", &n);
239
240                 if (reg != 0) {
241                         unsigned long total = 0;
242
243                         for (n /= sizeof(struct reg_property); n > 0; --n)
244                                 total += (reg++)->size;
245                         seq_printf(m, "memory\t\t: %luMB\n", total >> 20);
246                 }
247         }
248
249         /* Checks "l2cr-value" property in the registry */
250         np = find_devices("cpus");
251         if (np == 0)
252                 np = find_type_devices("cpu");
253         if (np != 0) {
254                 unsigned int *l2cr = (unsigned int *)
255                         get_property(np, "l2cr-value", NULL);
256                 if (l2cr != 0) {
257                         seq_printf(m, "l2cr override\t: 0x%x\n", *l2cr);
258                 }
259         }
260
261         /* Indicate newworld/oldworld */
262         seq_printf(m, "pmac-generation\t: %s\n",
263                    pmac_newworld ? "NewWorld" : "OldWorld");
264
265
266         return 0;
267 }
268
269 #ifdef CONFIG_VT
270 /*
271  * Dummy mksound function that does nothing.
272  * The real one is in the dmasound driver.
273  */
274 static void __pmac
275 pmac_mksound(unsigned int hz, unsigned int ticks)
276 {
277 }
278 #endif /* CONFIG_VT */
279
280 static volatile u32 *sysctrl_regs;
281
282 void __init
283 pmac_setup_arch(void)
284 {
285         struct device_node *cpu;
286         int *fp;
287         unsigned long pvr;
288
289         pvr = PVR_VER(mfspr(PVR));
290
291         /* Set loops_per_jiffy to a half-way reasonable value,
292            for use until calibrate_delay gets called. */
293         cpu = find_type_devices("cpu");
294         if (cpu != 0) {
295                 fp = (int *) get_property(cpu, "clock-frequency", NULL);
296                 if (fp != 0) {
297                         if (pvr == 4 || pvr >= 8)
298                                 /* 604, G3, G4 etc. */
299                                 loops_per_jiffy = *fp / HZ;
300                         else
301                                 /* 601, 603, etc. */
302                                 loops_per_jiffy = *fp / (2*HZ);
303                 } else
304                         loops_per_jiffy = 50000000 / HZ;
305         }
306
307         /* this area has the CPU identification register
308            and some registers used by smp boards */
309         sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);
310         ohare_init();
311
312         /* Lookup PCI hosts */
313         pmac_find_bridges();
314
315         /* Checks "l2cr-value" property in the registry */
316         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR) {
317                 struct device_node *np = find_devices("cpus");
318                 if (np == 0)
319                         np = find_type_devices("cpu");
320                 if (np != 0) {
321                         unsigned int *l2cr = (unsigned int *)
322                                 get_property(np, "l2cr-value", NULL);
323                         if (l2cr != 0) {
324                                 ppc_override_l2cr = 1;
325                                 ppc_override_l2cr_value = *l2cr;
326                                 _set_L2CR(0);
327                                 _set_L2CR(ppc_override_l2cr_value);
328                         }
329                 }
330         }
331
332         if (ppc_override_l2cr)
333                 printk(KERN_INFO "L2CR overriden (0x%x), backside cache is %s\n",
334                         ppc_override_l2cr_value, (ppc_override_l2cr_value & 0x80000000)
335                                 ? "enabled" : "disabled");
336
337 #ifdef CONFIG_KGDB
338         zs_kgdb_hook(0);
339 #endif
340
341 #ifdef CONFIG_ADB_CUDA
342         find_via_cuda();
343 #else
344         if (find_devices("via-cuda")) {
345                 printk("WARNING ! Your machine is Cuda based but your kernel\n");
346                 printk("          wasn't compiled with CONFIG_ADB_CUDA option !\n");
347         }
348 #endif
349 #ifdef CONFIG_ADB_PMU
350         find_via_pmu();
351 #else
352         if (find_devices("via-pmu")) {
353                 printk("WARNING ! Your machine is PMU based but your kernel\n");
354                 printk("          wasn't compiled with CONFIG_ADB_PMU option !\n");
355         }
356 #endif
357 #ifdef CONFIG_NVRAM
358         pmac_nvram_init();
359 #endif
360 #ifdef CONFIG_DUMMY_CONSOLE
361         conswitchp = &dummy_con;
362 #endif
363 #ifdef CONFIG_VT
364         kd_mksound = pmac_mksound;
365 #endif
366 #ifdef CONFIG_BLK_DEV_INITRD
367         if (initrd_start)
368                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
369         else
370 #endif
371                 ROOT_DEV = to_kdev_t(DEFAULT_ROOT_DEVICE);
372
373 #ifdef CONFIG_SMP
374         /* Check for Core99 */
375         if (find_devices("uni-n"))
376                 ppc_md.smp_ops = &core99_smp_ops;
377         else
378                 ppc_md.smp_ops = &psurge_smp_ops;
379 #endif /* CONFIG_SMP */
380
381         pci_create_OF_bus_map();
382 }
383
384 static void __init ohare_init(void)
385 {
386         /*
387          * Turn on the L2 cache.
388          * We assume that we have a PSX memory controller iff
389          * we have an ohare I/O controller.
390          */
391         if (find_devices("ohare") != NULL) {
392                 if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
393                         if (sysctrl_regs[4] & 0x10)
394                                 sysctrl_regs[4] |= 0x04000020;
395                         else
396                                 sysctrl_regs[4] |= 0x04000000;
397                         if(has_l2cache)
398                                 printk(KERN_INFO "Level 2 cache enabled\n");
399                 }
400         }
401 }
402
403 extern char *bootpath;
404 extern char *bootdevice;
405 void *boot_host;
406 int boot_target;
407 int boot_part;
408 extern kdev_t boot_dev;
409
410 void __init
411 pmac_init2(void)
412 {
413 #ifdef CONFIG_ADB_PMU
414         via_pmu_start();
415 #endif
416 #ifdef CONFIG_ADB_CUDA
417         via_cuda_start();
418 #endif
419 #ifdef CONFIG_PMAC_PBOOK
420         media_bay_init();
421 #endif
422         pmac_feature_late_init();
423 }
424
425 /* Borrowed from fs/partition/check.c */
426 static unsigned char* __init
427 read_one_block(struct block_device *bdev, unsigned long n, struct page **v)
428 {
429         struct address_space *mapping = bdev->bd_inode->i_mapping;
430         int sect = PAGE_CACHE_SIZE / 512;
431         struct page *page;
432
433         page = read_cache_page(mapping, n/sect,
434                         (filler_t *)mapping->a_ops->readpage, NULL);
435         if (!IS_ERR(page)) {
436                 wait_on_page(page);
437                 if (!Page_Uptodate(page))
438                         goto fail;
439                 if (PageError(page))
440                         goto fail;
441                 *v = page;
442                 return (unsigned char *)page_address(page) + 512 * (n % sect);
443 fail:
444                 page_cache_release(page);
445         }
446         *v = NULL;
447         return NULL;
448 }
449
450 #ifdef CONFIG_SCSI
451 void __init
452 note_scsi_host(struct device_node *node, void *host)
453 {
454         int l;
455         char *p;
456
457         l = strlen(node->full_name);
458         if (bootpath != NULL && bootdevice != NULL
459             && strncmp(node->full_name, bootdevice, l) == 0
460             && (bootdevice[l] == '/' || bootdevice[l] == 0)) {
461                 boot_host = host;
462                 /*
463                  * There's a bug in OF 1.0.5.  (Why am I not surprised.)
464                  * If you pass a path like scsi/sd@1:0 to canon, it returns
465                  * something like /bandit@F2000000/gc@10/53c94@10000/sd@0,0
466                  * That is, the scsi target number doesn't get preserved.
467                  * So we pick the target number out of bootpath and use that.
468                  */
469                 p = strstr(bootpath, "/sd@");
470                 if (p != NULL) {
471                         p += 4;
472                         boot_target = simple_strtoul(p, NULL, 10);
473                         p = strchr(p, ':');
474                         if (p != NULL)
475                                 boot_part = simple_strtoul(p + 1, NULL, 10);
476                 }
477         }
478 }
479 #endif /* CONFIG_SCSI */
480
481 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
482 kdev_t __init
483 find_ide_boot(void)
484 {
485         char *p;
486         int n;
487         kdev_t __init pmac_find_ide_boot(char *bootdevice, int n);
488
489         if (bootdevice == NULL)
490                 return 0;
491         p = strrchr(bootdevice, '/');
492         if (p == NULL)
493                 return 0;
494         n = p - bootdevice;
495
496         return pmac_find_ide_boot(bootdevice, n);
497 }
498 #endif /* CONFIG_BLK_DEV_IDE && CONFIG_BLK_DEV_IDE_PMAC */
499
500 void __init
501 find_boot_device(void)
502 {
503 #if defined(CONFIG_SCSI) && defined(CONFIG_BLK_DEV_SD)
504         if (boot_host != NULL) {
505                 boot_dev = sd_find_target(boot_host, boot_target);
506                 if (boot_dev != 0)
507                         return;
508         }
509 #endif
510 #if defined(CONFIG_BLK_DEV_IDE) && defined(CONFIG_BLK_DEV_IDE_PMAC)
511         boot_dev = find_ide_boot();
512 #endif
513 }
514
515 static void __init
516 check_bootable_part(kdev_t dev, int blk, struct mac_partition *part)
517 {
518         int goodness = 0;
519
520         macpart_fix_string(part->processor, 16);
521         macpart_fix_string(part->name, 32);
522         macpart_fix_string(part->type, 32);
523
524         if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
525             && strcasecmp(part->processor, "powerpc") == 0)
526                 goodness++;
527
528         if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
529             || (strnicmp(part->type, "Linux", 5) == 0
530             && strcasecmp(part->type, "Linux_swap") != 0)) {
531                 int i, l;
532
533                 goodness++;
534                 l = strlen(part->name);
535                 if (strcmp(part->name, "/") == 0)
536                         goodness++;
537                 for (i = 0; i <= l - 4; ++i) {
538                         if (strnicmp(part->name + i, "root",
539                                      4) == 0) {
540                                 goodness += 2;
541                                 break;
542                         }
543                 }
544                 if (strnicmp(part->name, "swap", 4) == 0)
545                         goodness--;
546         }
547
548         if (goodness > current_root_goodness) {
549                 ROOT_DEV = MKDEV(MAJOR(dev), MINOR(dev) + blk);
550                 current_root_goodness = goodness;
551         }
552 }
553
554 static void __init
555 check_bootable_disk(kdev_t dev, struct block_device *bdev)
556 {
557         struct mac_partition *part;
558         struct mac_driver_desc *md;
559         struct page* pg;
560         unsigned secsize, blocks_in_map, blk;
561         unsigned char* data;
562
563         /* Check driver descriptor */
564         md = (struct mac_driver_desc *) read_one_block(bdev, 0, &pg);
565         if (!md)
566                 return;
567         if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC)
568                 goto fail;
569         secsize = be16_to_cpu(md->block_size);
570         page_cache_release(pg);
571
572         /* Check if it looks like a mac partition map */
573         data = read_one_block(bdev, secsize/512, &pg);
574         if (!data)
575                 goto fail;
576         part = (struct mac_partition *) (data + secsize%512);
577         if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
578                 goto fail;
579
580         /* Iterate the partition map */
581         blocks_in_map = be32_to_cpu(part->map_count);
582         for (blk = 1; blk <= blocks_in_map; ++blk) {
583                 int pos = blk * secsize;
584                 page_cache_release(pg);
585                 data = read_one_block(bdev, pos/512, &pg);
586                 if (!data)
587                         break;
588                 part = (struct mac_partition *) (data + pos%512);
589                 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
590                         break;
591                 check_bootable_part(dev, blk, part);
592         }
593 fail:
594         if (pg)
595                 page_cache_release(pg);
596 }
597
598 static int __init
599 walk_bootable(struct gendisk *hd, void *data)
600 {
601         int drive;
602
603         for (drive=0; drive<hd->nr_real; drive++) {
604                 kdev_t dev;
605                 struct block_device *bdev;
606                 int rc;
607
608                 dev = MKDEV(hd->major, drive << hd->minor_shift);
609                 if (boot_dev && boot_dev != dev)
610                         continue;
611                 bdev = bdget(kdev_t_to_nr(dev));
612                 if (bdev == NULL)
613                         continue;
614                 rc = blkdev_get(bdev, FMODE_READ, 0, BDEV_RAW);
615                 if (rc == 0) {
616                         check_bootable_disk(dev, bdev);
617                         blkdev_put(bdev, BDEV_RAW);
618                 }
619         }
620
621         return 0;
622 }
623
624 void __init
625 pmac_discover_root(void)
626 {
627         char* p;
628
629         /* Check if root devices already got selected by other ways */
630         if (ROOT_DEV != to_kdev_t(DEFAULT_ROOT_DEVICE))
631                 return;
632         p = strstr(saved_command_line, "root=");
633         if (p != NULL && (p == saved_command_line || p[-1] == ' '))
634                 return;
635
636         /* Find the device used for booting if we can */
637         find_boot_device();
638
639         /* Try to locate a partition */
640         walk_gendisk(walk_bootable, NULL);
641 }
642
643 void __pmac
644 pmac_restart(char *cmd)
645 {
646 #ifdef CONFIG_ADB_CUDA
647         struct adb_request req;
648 #endif /* CONFIG_ADB_CUDA */
649
650 #ifdef CONFIG_NVRAM
651         pmac_nvram_update();
652 #endif
653
654         switch (sys_ctrler) {
655 #ifdef CONFIG_ADB_CUDA
656         case SYS_CTRLER_CUDA:
657                 cuda_request(&req, NULL, 2, CUDA_PACKET,
658                              CUDA_RESET_SYSTEM);
659                 for (;;)
660                         cuda_poll();
661                 break;
662 #endif /* CONFIG_ADB_CUDA */
663 #ifdef CONFIG_ADB_PMU
664         case SYS_CTRLER_PMU:
665                 pmu_restart();
666                 break;
667 #endif /* CONFIG_ADB_PMU */
668         default: ;
669         }
670 }
671
672 void __pmac
673 pmac_power_off(void)
674 {
675 #ifdef CONFIG_ADB_CUDA
676         struct adb_request req;
677 #endif /* CONFIG_ADB_CUDA */
678
679 #ifdef CONFIG_NVRAM
680         pmac_nvram_update();
681 #endif
682
683         switch (sys_ctrler) {
684 #ifdef CONFIG_ADB_CUDA
685         case SYS_CTRLER_CUDA:
686                 cuda_request(&req, NULL, 2, CUDA_PACKET,
687                              CUDA_POWERDOWN);
688                 for (;;)
689                         cuda_poll();
690                 break;
691 #endif /* CONFIG_ADB_CUDA */
692 #ifdef CONFIG_ADB_PMU
693         case SYS_CTRLER_PMU:
694                 pmu_shutdown();
695                 break;
696 #endif /* CONFIG_ADB_PMU */
697         default: ;
698         }
699 }
700
701 void __pmac
702 pmac_halt(void)
703 {
704    pmac_power_off();
705 }
706
707
708 /*
709  * Read in a property describing some pieces of memory.
710  */
711
712 static int __init
713 get_mem_prop(char *name, struct mem_pieces *mp)
714 {
715         struct reg_property *rp;
716         int i, s;
717         unsigned int *ip;
718         int nac = prom_n_addr_cells(memory_node);
719         int nsc = prom_n_size_cells(memory_node);
720
721         ip = (unsigned int *) get_property(memory_node, name, &s);
722         if (ip == NULL) {
723                 printk(KERN_ERR "error: couldn't get %s property on /memory\n",
724                        name);
725                 return 0;
726         }
727         s /= (nsc + nac) * 4;
728         rp = mp->regions;
729         for (i = 0; i < s; ++i, ip += nac+nsc) {
730                 if (nac >= 2 && ip[nac-2] != 0)
731                         continue;
732                 rp->address = ip[nac-1];
733                 if (nsc >= 2 && ip[nac+nsc-2] != 0)
734                         rp->size = ~0U;
735                 else
736                         rp->size = ip[nac+nsc-1];
737                 ++rp;
738         }
739         mp->n_regions = rp - mp->regions;
740
741         /* Make sure the pieces are sorted. */
742         mem_pieces_sort(mp);
743         mem_pieces_coalesce(mp);
744         return 1;
745 }
746
747 /*
748  * On systems with Open Firmware, collect information about
749  * physical RAM and which pieces are already in use.
750  * At this point, we have (at least) the first 8MB mapped with a BAT.
751  * Our text, data, bss use something over 1MB, starting at 0.
752  * Open Firmware may be using 1MB at the 4MB point.
753  */
754 unsigned long __init
755 pmac_find_end_of_memory(void)
756 {
757         unsigned long a, total;
758         struct mem_pieces phys_mem;
759
760         /*
761          * Find out where physical memory is, and check that it
762          * starts at 0 and is contiguous.  It seems that RAM is
763          * always physically contiguous on Power Macintoshes.
764          *
765          * Supporting discontiguous physical memory isn't hard,
766          * it just makes the virtual <-> physical mapping functions
767          * more complicated (or else you end up wasting space
768          * in mem_map).
769          */
770         memory_node = find_devices("memory");
771         if (memory_node == NULL || !get_mem_prop("reg", &phys_mem)
772             || phys_mem.n_regions == 0)
773                 panic("No RAM??");
774         a = phys_mem.regions[0].address;
775         if (a != 0)
776                 panic("RAM doesn't start at physical address 0");
777         total = phys_mem.regions[0].size;
778
779         if (phys_mem.n_regions > 1) {
780                 printk("RAM starting at 0x%x is not contiguous\n",
781                        phys_mem.regions[1].address);
782                 printk("Using RAM from 0 to 0x%lx\n", total-1);
783         }
784
785         return total;
786 }
787
788 void __init
789 select_adb_keyboard(void)
790 {
791 #ifdef CONFIG_VT
792 #ifdef CONFIG_INPUT
793         ppc_md.kbd_init_hw       = mac_hid_init_hw;
794         ppc_md.kbd_translate     = mac_hid_kbd_translate;
795         ppc_md.kbd_unexpected_up = mac_hid_kbd_unexpected_up;
796         ppc_md.kbd_setkeycode    = 0;
797         ppc_md.kbd_getkeycode    = 0;
798         ppc_md.kbd_leds          = 0;
799 #ifdef CONFIG_MAGIC_SYSRQ
800 #ifdef CONFIG_MAC_ADBKEYCODES
801         if (!keyboard_sends_linux_keycodes) {
802                 ppc_md.ppc_kbd_sysrq_xlate = mac_hid_kbd_sysrq_xlate;
803                 SYSRQ_KEY = 0x69;
804         } else
805 #endif /* CONFIG_MAC_ADBKEYCODES */
806         {
807                 ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
808                 SYSRQ_KEY = 0x54;
809         }
810 #endif /* CONFIG_MAGIC_SYSRQ */
811 #elif defined(CONFIG_ADB_KEYBOARD)
812         ppc_md.kbd_setkeycode       = mackbd_setkeycode;
813         ppc_md.kbd_getkeycode       = mackbd_getkeycode;
814         ppc_md.kbd_translate        = mackbd_translate;
815         ppc_md.kbd_unexpected_up    = mackbd_unexpected_up;
816         ppc_md.kbd_leds             = mackbd_leds;
817         ppc_md.kbd_init_hw          = mackbd_init_hw;
818 #ifdef CONFIG_MAGIC_SYSRQ
819         ppc_md.ppc_kbd_sysrq_xlate  = mackbd_sysrq_xlate;
820         SYSRQ_KEY = 0x69;
821 #endif /* CONFIG_MAGIC_SYSRQ */
822 #endif /* CONFIG_INPUT_ADBHID/CONFIG_ADB_KEYBOARD */
823 #endif /* CONFIG_VT */
824 }
825
826 void __init
827 pmac_init(unsigned long r3, unsigned long r4, unsigned long r5,
828           unsigned long r6, unsigned long r7)
829 {
830         /* isa_io_base gets set in pmac_find_bridges */
831         isa_mem_base = PMAC_ISA_MEM_BASE;
832         pci_dram_offset = PMAC_PCI_DRAM_OFFSET;
833         ISA_DMA_THRESHOLD = ~0L;
834         DMA_MODE_READ = 1;
835         DMA_MODE_WRITE = 2;
836
837         ppc_md.setup_arch     = pmac_setup_arch;
838         ppc_md.show_cpuinfo   = pmac_show_cpuinfo;
839         ppc_md.show_percpuinfo = of_show_percpuinfo;
840         ppc_md.irq_cannonicalize = NULL;
841         ppc_md.init_IRQ       = pmac_pic_init;
842         ppc_md.get_irq        = pmac_get_irq; /* Changed later on ... */
843         ppc_md.init           = pmac_init2;
844
845         ppc_md.pcibios_fixup  = pmac_pcibios_fixup;
846         ppc_md.pcibios_enable_device_hook = pmac_pci_enable_device_hook;
847         ppc_md.pcibios_after_init = pmac_pcibios_after_init;
848
849         ppc_md.discover_root  = pmac_discover_root;
850
851         ppc_md.restart        = pmac_restart;
852         ppc_md.power_off      = pmac_power_off;
853         ppc_md.halt           = pmac_halt;
854
855         ppc_md.time_init      = pmac_time_init;
856         ppc_md.set_rtc_time   = pmac_set_rtc_time;
857         ppc_md.get_rtc_time   = pmac_get_rtc_time;
858         ppc_md.calibrate_decr = pmac_calibrate_decr;
859
860         ppc_md.find_end_of_memory = pmac_find_end_of_memory;
861
862         ppc_md.feature_call   = pmac_do_feature_call;
863
864         select_adb_keyboard();
865
866 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
867 #ifdef CONFIG_BLK_DEV_IDE_PMAC
868         ppc_ide_md.ide_init_hwif        = pmac_ide_init_hwif_ports;
869         ppc_ide_md.default_io_base      = pmac_ide_get_base;
870 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
871 #endif /* defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) */
872
873 #ifdef CONFIG_BOOTX_TEXT
874         ppc_md.progress = pmac_progress;
875 #endif /* CONFIG_BOOTX_TEXT */
876
877         if (ppc_md.progress) ppc_md.progress("pmac_init(): exit", 0);
878
879 }
880
881 #ifdef CONFIG_BOOTX_TEXT
882 void __init
883 pmac_progress(char *s, unsigned short hex)
884 {
885         if (boot_text_mapped) {
886                 btext_drawstring(s);
887                 btext_drawchar('\n');
888         }
889 }
890 #endif /* CONFIG_BOOTX_TEXT */