chrp_setup.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * arch/ppc/platforms/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Adapted from 'alpha' version by Gary Thomas
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. */
  8. /*
  9. * bootup setup stuff..
  10. */
  11. #include <linux/config.h>
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/stddef.h>
  17. #include <linux/unistd.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/slab.h>
  20. #include <linux/user.h>
  21. #include <linux/a.out.h>
  22. #include <linux/tty.h>
  23. #include <linux/major.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/reboot.h>
  26. #include <linux/init.h>
  27. #include <linux/pci.h>
  28. #include <linux/version.h>
  29. #include <linux/adb.h>
  30. #include <linux/module.h>
  31. #include <linux/delay.h>
  32. #include <linux/ide.h>
  33. #include <linux/console.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/root_dev.h>
  36. #include <linux/initrd.h>
  37. #include <linux/module.h>
  38. #include <asm/io.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/prom.h>
  41. #include <asm/gg2.h>
  42. #include <asm/pci-bridge.h>
  43. #include <asm/dma.h>
  44. #include <asm/machdep.h>
  45. #include <asm/irq.h>
  46. #include <asm/hydra.h>
  47. #include <asm/sections.h>
  48. #include <asm/time.h>
  49. #include <asm/btext.h>
  50. #include <asm/i8259.h>
  51. #include <asm/open_pic.h>
  52. #include <asm/xmon.h>
  53. unsigned long chrp_get_rtc_time(void);
  54. int chrp_set_rtc_time(unsigned long nowtime);
  55. void chrp_calibrate_decr(void);
  56. long chrp_time_init(void);
  57. void chrp_find_bridges(void);
  58. void chrp_event_scan(void);
  59. void rtas_display_progress(char *, unsigned short);
  60. void rtas_indicator_progress(char *, unsigned short);
  61. void btext_progress(char *, unsigned short);
  62. extern unsigned long pmac_find_end_of_memory(void);
  63. extern int of_show_percpuinfo(struct seq_file *, int);
  64. int _chrp_type;
  65. EXPORT_SYMBOL(_chrp_type);
  66. /*
  67. * XXX this should be in xmon.h, but putting it there means xmon.h
  68. * has to include <linux/interrupt.h> (to get irqreturn_t), which
  69. * causes all sorts of problems. -- paulus
  70. */
  71. extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
  72. extern dev_t boot_dev;
  73. extern PTE *Hash, *Hash_end;
  74. extern unsigned long Hash_size, Hash_mask;
  75. extern int probingmem;
  76. extern unsigned long loops_per_jiffy;
  77. static int max_width;
  78. #ifdef CONFIG_SMP
  79. extern struct smp_ops_t chrp_smp_ops;
  80. #endif
  81. static const char *gg2_memtypes[4] = {
  82. "FPM", "SDRAM", "EDO", "BEDO"
  83. };
  84. static const char *gg2_cachesizes[4] = {
  85. "256 KB", "512 KB", "1 MB", "Reserved"
  86. };
  87. static const char *gg2_cachetypes[4] = {
  88. "Asynchronous", "Reserved", "Flow-Through Synchronous",
  89. "Pipelined Synchronous"
  90. };
  91. static const char *gg2_cachemodes[4] = {
  92. "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
  93. };
  94. int __chrp
  95. chrp_show_cpuinfo(struct seq_file *m)
  96. {
  97. int i, sdramen;
  98. unsigned int t;
  99. struct device_node *root;
  100. const char *model = "";
  101. root = find_path_device("/");
  102. if (root)
  103. model = get_property(root, "model", NULL);
  104. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  105. /* longtrail (goldengate) stuff */
  106. if (!strncmp(model, "IBM,LongTrail", 13)) {
  107. /* VLSI VAS96011/12 `Golden Gate 2' */
  108. /* Memory banks */
  109. sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
  110. >>31) & 1;
  111. for (i = 0; i < (sdramen ? 4 : 6); i++) {
  112. t = in_le32(gg2_pci_config_base+
  113. GG2_PCI_DRAM_BANK0+
  114. i*4);
  115. if (!(t & 1))
  116. continue;
  117. switch ((t>>8) & 0x1f) {
  118. case 0x1f:
  119. model = "4 MB";
  120. break;
  121. case 0x1e:
  122. model = "8 MB";
  123. break;
  124. case 0x1c:
  125. model = "16 MB";
  126. break;
  127. case 0x18:
  128. model = "32 MB";
  129. break;
  130. case 0x10:
  131. model = "64 MB";
  132. break;
  133. case 0x00:
  134. model = "128 MB";
  135. break;
  136. default:
  137. model = "Reserved";
  138. break;
  139. }
  140. seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
  141. gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
  142. }
  143. /* L2 cache */
  144. t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
  145. seq_printf(m, "board l2\t: %s %s (%s)\n",
  146. gg2_cachesizes[(t>>7) & 3],
  147. gg2_cachetypes[(t>>2) & 3],
  148. gg2_cachemodes[t & 3]);
  149. }
  150. return 0;
  151. }
  152. /*
  153. * Fixes for the National Semiconductor PC78308VUL SuperI/O
  154. *
  155. * Some versions of Open Firmware incorrectly initialize the IRQ settings
  156. * for keyboard and mouse
  157. */
  158. static inline void __init sio_write(u8 val, u8 index)
  159. {
  160. outb(index, 0x15c);
  161. outb(val, 0x15d);
  162. }
  163. static inline u8 __init sio_read(u8 index)
  164. {
  165. outb(index, 0x15c);
  166. return inb(0x15d);
  167. }
  168. static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
  169. u8 type)
  170. {
  171. u8 level0, type0, active;
  172. /* select logical device */
  173. sio_write(device, 0x07);
  174. active = sio_read(0x30);
  175. level0 = sio_read(0x70);
  176. type0 = sio_read(0x71);
  177. if (level0 != level || type0 != type || !active) {
  178. printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
  179. "remapping to level %d, type %d, active\n",
  180. name, level0, type0, !active ? "in" : "", level, type);
  181. sio_write(0x01, 0x30);
  182. sio_write(level, 0x70);
  183. sio_write(type, 0x71);
  184. }
  185. }
  186. static void __init sio_init(void)
  187. {
  188. struct device_node *root;
  189. if ((root = find_path_device("/")) &&
  190. !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
  191. /* logical device 0 (KBC/Keyboard) */
  192. sio_fixup_irq("keyboard", 0, 1, 2);
  193. /* select logical device 1 (KBC/Mouse) */
  194. sio_fixup_irq("mouse", 1, 12, 2);
  195. }
  196. }
  197. static void __init pegasos_set_l2cr(void)
  198. {
  199. struct device_node *np;
  200. /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
  201. if (_chrp_type != _CHRP_Pegasos)
  202. return;
  203. /* Enable L2 cache if needed */
  204. np = find_type_devices("cpu");
  205. if (np != NULL) {
  206. unsigned int *l2cr = (unsigned int *)
  207. get_property (np, "l2cr", NULL);
  208. if (l2cr == NULL) {
  209. printk ("Pegasos l2cr : no cpu l2cr property found\n");
  210. return;
  211. }
  212. if (!((*l2cr) & 0x80000000)) {
  213. printk ("Pegasos l2cr : L2 cache was not active, "
  214. "activating\n");
  215. _set_L2CR(0);
  216. _set_L2CR((*l2cr) | 0x80000000);
  217. }
  218. }
  219. }
  220. void __init chrp_setup_arch(void)
  221. {
  222. struct device_node *device;
  223. /* init to some ~sane value until calibrate_delay() runs */
  224. loops_per_jiffy = 50000000/HZ;
  225. #ifdef CONFIG_BLK_DEV_INITRD
  226. /* this is fine for chrp */
  227. initrd_below_start_ok = 1;
  228. if (initrd_start)
  229. ROOT_DEV = Root_RAM0;
  230. else
  231. #endif
  232. ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
  233. /* On pegasos, enable the L2 cache if not already done by OF */
  234. pegasos_set_l2cr();
  235. /* Lookup PCI host bridges */
  236. chrp_find_bridges();
  237. #ifndef CONFIG_PPC64BRIDGE
  238. /*
  239. * Temporary fixes for PCI devices.
  240. * -- Geert
  241. */
  242. hydra_init(); /* Mac I/O */
  243. #endif /* CONFIG_PPC64BRIDGE */
  244. /*
  245. * Fix the Super I/O configuration
  246. */
  247. sio_init();
  248. /* Get the event scan rate for the rtas so we know how
  249. * often it expects a heartbeat. -- Cort
  250. */
  251. if ( rtas_data ) {
  252. struct property *p;
  253. device = find_devices("rtas");
  254. for ( p = device->properties;
  255. p && strncmp(p->name, "rtas-event-scan-rate", 20);
  256. p = p->next )
  257. /* nothing */ ;
  258. if ( p && *(unsigned long *)p->value ) {
  259. ppc_md.heartbeat = chrp_event_scan;
  260. ppc_md.heartbeat_reset = (HZ/(*(unsigned long *)p->value)*30)-1;
  261. ppc_md.heartbeat_count = 1;
  262. printk("RTAS Event Scan Rate: %lu (%lu jiffies)\n",
  263. *(unsigned long *)p->value, ppc_md.heartbeat_reset );
  264. }
  265. }
  266. pci_create_OF_bus_map();
  267. }
  268. void __chrp
  269. chrp_event_scan(void)
  270. {
  271. unsigned char log[1024];
  272. unsigned long ret = 0;
  273. /* XXX: we should loop until the hardware says no more error logs -- Cort */
  274. call_rtas( "event-scan", 4, 1, &ret, 0xffffffff, 0,
  275. __pa(log), 1024 );
  276. ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
  277. }
  278. void __chrp
  279. chrp_restart(char *cmd)
  280. {
  281. printk("RTAS system-reboot returned %d\n",
  282. call_rtas("system-reboot", 0, 1, NULL));
  283. for (;;);
  284. }
  285. void __chrp
  286. chrp_power_off(void)
  287. {
  288. /* allow power on only with power button press */
  289. printk("RTAS power-off returned %d\n",
  290. call_rtas("power-off", 2, 1, NULL,0xffffffff,0xffffffff));
  291. for (;;);
  292. }
  293. void __chrp
  294. chrp_halt(void)
  295. {
  296. chrp_power_off();
  297. }
  298. u_int __chrp
  299. chrp_irq_canonicalize(u_int irq)
  300. {
  301. if (irq == 2)
  302. return 9;
  303. return irq;
  304. }
  305. /*
  306. * Finds the open-pic node and sets OpenPIC_Addr based on its reg property.
  307. * Then checks if it has an interrupt-ranges property. If it does then
  308. * we have a distributed open-pic, so call openpic_set_sources to tell
  309. * the openpic code where to find the interrupt source registers.
  310. */
  311. static void __init chrp_find_openpic(void)
  312. {
  313. struct device_node *np;
  314. int len, i;
  315. unsigned int *iranges;
  316. void __iomem *isu;
  317. np = find_type_devices("open-pic");
  318. if (np == NULL || np->n_addrs == 0)
  319. return;
  320. printk(KERN_INFO "OpenPIC at %x (size %x)\n",
  321. np->addrs[0].address, np->addrs[0].size);
  322. OpenPIC_Addr = ioremap(np->addrs[0].address, 0x40000);
  323. if (OpenPIC_Addr == NULL) {
  324. printk(KERN_ERR "Failed to map OpenPIC!\n");
  325. return;
  326. }
  327. iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
  328. if (iranges == NULL || len < 2 * sizeof(unsigned int))
  329. return; /* not distributed */
  330. /*
  331. * The first pair of cells in interrupt-ranges refers to the
  332. * IDU; subsequent pairs refer to the ISUs.
  333. */
  334. len /= 2 * sizeof(unsigned int);
  335. if (np->n_addrs < len) {
  336. printk(KERN_ERR "Insufficient addresses for distributed"
  337. " OpenPIC (%d < %d)\n", np->n_addrs, len);
  338. return;
  339. }
  340. if (iranges[1] != 0) {
  341. printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
  342. iranges[0], iranges[0] + iranges[1] - 1);
  343. openpic_set_sources(iranges[0], iranges[1], NULL);
  344. }
  345. for (i = 1; i < len; ++i) {
  346. iranges += 2;
  347. printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x (%x)\n",
  348. iranges[0], iranges[0] + iranges[1] - 1,
  349. np->addrs[i].address, np->addrs[i].size);
  350. isu = ioremap(np->addrs[i].address, np->addrs[i].size);
  351. if (isu != NULL)
  352. openpic_set_sources(iranges[0], iranges[1], isu);
  353. else
  354. printk(KERN_ERR "Failed to map OpenPIC ISU at %x!\n",
  355. np->addrs[i].address);
  356. }
  357. }
  358. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  359. static struct irqaction xmon_irqaction = {
  360. .handler = xmon_irq,
  361. .mask = CPU_MASK_NONE,
  362. .name = "XMON break",
  363. };
  364. #endif
  365. void __init chrp_init_IRQ(void)
  366. {
  367. struct device_node *np;
  368. int i;
  369. unsigned long chrp_int_ack = 0;
  370. unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
  371. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  372. struct device_node *kbd;
  373. #endif
  374. for (np = find_devices("pci"); np != NULL; np = np->next) {
  375. unsigned int *addrp = (unsigned int *)
  376. get_property(np, "8259-interrupt-acknowledge", NULL);
  377. if (addrp == NULL)
  378. continue;
  379. chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
  380. break;
  381. }
  382. if (np == NULL)
  383. printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
  384. chrp_find_openpic();
  385. if (OpenPIC_Addr) {
  386. prom_get_irq_senses(init_senses, NUM_8259_INTERRUPTS, NR_IRQS);
  387. OpenPIC_InitSenses = init_senses;
  388. OpenPIC_NumInitSenses = NR_IRQS - NUM_8259_INTERRUPTS;
  389. openpic_init(NUM_8259_INTERRUPTS);
  390. /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
  391. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  392. i8259_irq);
  393. }
  394. for (i = 0; i < NUM_8259_INTERRUPTS; i++)
  395. irq_desc[i].handler = &i8259_pic;
  396. i8259_init(chrp_int_ack);
  397. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  398. /* see if there is a keyboard in the device tree
  399. with a parent of type "adb" */
  400. for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
  401. if (kbd->parent && kbd->parent->type
  402. && strcmp(kbd->parent->type, "adb") == 0)
  403. break;
  404. if (kbd)
  405. setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
  406. #endif
  407. }
  408. void __init
  409. chrp_init2(void)
  410. {
  411. #ifdef CONFIG_NVRAM
  412. // XX replace this in a more saner way
  413. // pmac_nvram_init();
  414. #endif
  415. request_region(0x20,0x20,"pic1");
  416. request_region(0xa0,0x20,"pic2");
  417. request_region(0x00,0x20,"dma1");
  418. request_region(0x40,0x20,"timer");
  419. request_region(0x80,0x10,"dma page reg");
  420. request_region(0xc0,0x20,"dma2");
  421. if (ppc_md.progress)
  422. ppc_md.progress(" Have fun! ", 0x7777);
  423. }
  424. void __init
  425. chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
  426. unsigned long r6, unsigned long r7)
  427. {
  428. struct device_node *root = find_path_device ("/");
  429. char *machine = NULL;
  430. #ifdef CONFIG_BLK_DEV_INITRD
  431. /* take care of initrd if we have one */
  432. if ( r6 )
  433. {
  434. initrd_start = r6 + KERNELBASE;
  435. initrd_end = r6 + r7 + KERNELBASE;
  436. }
  437. #endif /* CONFIG_BLK_DEV_INITRD */
  438. ISA_DMA_THRESHOLD = ~0L;
  439. DMA_MODE_READ = 0x44;
  440. DMA_MODE_WRITE = 0x48;
  441. isa_io_base = CHRP_ISA_IO_BASE; /* default value */
  442. if (root)
  443. machine = get_property(root, "model", NULL);
  444. if (machine && strncmp(machine, "Pegasos", 7) == 0) {
  445. _chrp_type = _CHRP_Pegasos;
  446. } else if (machine && strncmp(machine, "IBM", 3) == 0) {
  447. _chrp_type = _CHRP_IBM;
  448. } else if (machine && strncmp(machine, "MOT", 3) == 0) {
  449. _chrp_type = _CHRP_Motorola;
  450. } else {
  451. /* Let's assume it is an IBM chrp if all else fails */
  452. _chrp_type = _CHRP_IBM;
  453. }
  454. ppc_md.setup_arch = chrp_setup_arch;
  455. ppc_md.show_percpuinfo = of_show_percpuinfo;
  456. ppc_md.show_cpuinfo = chrp_show_cpuinfo;
  457. ppc_md.irq_canonicalize = chrp_irq_canonicalize;
  458. ppc_md.init_IRQ = chrp_init_IRQ;
  459. if (_chrp_type == _CHRP_Pegasos)
  460. ppc_md.get_irq = i8259_irq;
  461. else
  462. ppc_md.get_irq = openpic_get_irq;
  463. ppc_md.init = chrp_init2;
  464. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  465. ppc_md.restart = chrp_restart;
  466. ppc_md.power_off = chrp_power_off;
  467. ppc_md.halt = chrp_halt;
  468. ppc_md.time_init = chrp_time_init;
  469. ppc_md.set_rtc_time = chrp_set_rtc_time;
  470. ppc_md.get_rtc_time = chrp_get_rtc_time;
  471. ppc_md.calibrate_decr = chrp_calibrate_decr;
  472. ppc_md.find_end_of_memory = pmac_find_end_of_memory;
  473. if (rtas_data) {
  474. struct device_node *rtas;
  475. unsigned int *p;
  476. rtas = find_devices("rtas");
  477. if (rtas != NULL) {
  478. if (get_property(rtas, "display-character", NULL)) {
  479. ppc_md.progress = rtas_display_progress;
  480. p = (unsigned int *) get_property
  481. (rtas, "ibm,display-line-length", NULL);
  482. if (p)
  483. max_width = *p;
  484. } else if (get_property(rtas, "set-indicator", NULL))
  485. ppc_md.progress = rtas_indicator_progress;
  486. }
  487. }
  488. #ifdef CONFIG_BOOTX_TEXT
  489. if (ppc_md.progress == NULL && boot_text_mapped)
  490. ppc_md.progress = btext_progress;
  491. #endif
  492. #ifdef CONFIG_SMP
  493. ppc_md.smp_ops = &chrp_smp_ops;
  494. #endif /* CONFIG_SMP */
  495. /*
  496. * Print the banner, then scroll down so boot progress
  497. * can be printed. -- Cort
  498. */
  499. if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
  500. }
  501. void __chrp
  502. rtas_display_progress(char *s, unsigned short hex)
  503. {
  504. int width;
  505. char *os = s;
  506. if ( call_rtas( "display-character", 1, 1, NULL, '\r' ) )
  507. return;
  508. width = max_width;
  509. while ( *os )
  510. {
  511. if ( (*os == '\n') || (*os == '\r') )
  512. width = max_width;
  513. else
  514. width--;
  515. call_rtas( "display-character", 1, 1, NULL, *os++ );
  516. /* if we overwrite the screen length */
  517. if ( width == 0 )
  518. while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
  519. os++;
  520. }
  521. /*while ( width-- > 0 )*/
  522. call_rtas( "display-character", 1, 1, NULL, ' ' );
  523. }
  524. void __chrp
  525. rtas_indicator_progress(char *s, unsigned short hex)
  526. {
  527. call_rtas("set-indicator", 3, 1, NULL, 6, 0, hex);
  528. }
  529. #ifdef CONFIG_BOOTX_TEXT
  530. void
  531. btext_progress(char *s, unsigned short hex)
  532. {
  533. prom_print(s);
  534. prom_print("\n");
  535. }
  536. #endif /* CONFIG_BOOTX_TEXT */