pmac_setup.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:23k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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