chrp_setup.c 15 KB

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