setup.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. * Adapted from 'alpha' version by Gary Thomas
  4. * Modified by Cort Dougan (cort@cs.nmt.edu)
  5. */
  6. /*
  7. * bootup setup stuff..
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/stddef.h>
  14. #include <linux/unistd.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/user.h>
  17. #include <linux/tty.h>
  18. #include <linux/major.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/reboot.h>
  21. #include <linux/init.h>
  22. #include <linux/pci.h>
  23. #include <generated/utsrelease.h>
  24. #include <linux/adb.h>
  25. #include <linux/module.h>
  26. #include <linux/delay.h>
  27. #include <linux/console.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/root_dev.h>
  30. #include <linux/initrd.h>
  31. #include <linux/timer.h>
  32. #include <asm/io.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/prom.h>
  35. #include <asm/pci-bridge.h>
  36. #include <asm/dma.h>
  37. #include <asm/machdep.h>
  38. #include <asm/irq.h>
  39. #include <asm/hydra.h>
  40. #include <asm/sections.h>
  41. #include <asm/time.h>
  42. #include <asm/i8259.h>
  43. #include <asm/mpic.h>
  44. #include <asm/rtas.h>
  45. #include <asm/xmon.h>
  46. #include "chrp.h"
  47. #include "gg2.h"
  48. void rtas_indicator_progress(char *, unsigned short);
  49. int _chrp_type;
  50. EXPORT_SYMBOL(_chrp_type);
  51. static struct mpic *chrp_mpic;
  52. /* Used for doing CHRP event-scans */
  53. DEFINE_PER_CPU(struct timer_list, heartbeat_timer);
  54. unsigned long event_scan_interval;
  55. extern unsigned long loops_per_jiffy;
  56. /* To be replaced by RTAS when available */
  57. static unsigned int __iomem *briq_SPOR;
  58. #ifdef CONFIG_SMP
  59. extern struct smp_ops_t chrp_smp_ops;
  60. #endif
  61. static const char *gg2_memtypes[4] = {
  62. "FPM", "SDRAM", "EDO", "BEDO"
  63. };
  64. static const char *gg2_cachesizes[4] = {
  65. "256 KB", "512 KB", "1 MB", "Reserved"
  66. };
  67. static const char *gg2_cachetypes[4] = {
  68. "Asynchronous", "Reserved", "Flow-Through Synchronous",
  69. "Pipelined Synchronous"
  70. };
  71. static const char *gg2_cachemodes[4] = {
  72. "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
  73. };
  74. static const char *chrp_names[] = {
  75. "Unknown",
  76. "","","",
  77. "Motorola",
  78. "IBM or Longtrail",
  79. "Genesi Pegasos",
  80. "Total Impact Briq"
  81. };
  82. void chrp_show_cpuinfo(struct seq_file *m)
  83. {
  84. int i, sdramen;
  85. unsigned int t;
  86. struct device_node *root;
  87. const char *model = "";
  88. root = of_find_node_by_path("/");
  89. if (root)
  90. model = of_get_property(root, "model", NULL);
  91. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  92. /* longtrail (goldengate) stuff */
  93. if (model && !strncmp(model, "IBM,LongTrail", 13)) {
  94. /* VLSI VAS96011/12 `Golden Gate 2' */
  95. /* Memory banks */
  96. sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
  97. >>31) & 1;
  98. for (i = 0; i < (sdramen ? 4 : 6); i++) {
  99. t = in_le32(gg2_pci_config_base+
  100. GG2_PCI_DRAM_BANK0+
  101. i*4);
  102. if (!(t & 1))
  103. continue;
  104. switch ((t>>8) & 0x1f) {
  105. case 0x1f:
  106. model = "4 MB";
  107. break;
  108. case 0x1e:
  109. model = "8 MB";
  110. break;
  111. case 0x1c:
  112. model = "16 MB";
  113. break;
  114. case 0x18:
  115. model = "32 MB";
  116. break;
  117. case 0x10:
  118. model = "64 MB";
  119. break;
  120. case 0x00:
  121. model = "128 MB";
  122. break;
  123. default:
  124. model = "Reserved";
  125. break;
  126. }
  127. seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
  128. gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
  129. }
  130. /* L2 cache */
  131. t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
  132. seq_printf(m, "board l2\t: %s %s (%s)\n",
  133. gg2_cachesizes[(t>>7) & 3],
  134. gg2_cachetypes[(t>>2) & 3],
  135. gg2_cachemodes[t & 3]);
  136. }
  137. of_node_put(root);
  138. }
  139. /*
  140. * Fixes for the National Semiconductor PC78308VUL SuperI/O
  141. *
  142. * Some versions of Open Firmware incorrectly initialize the IRQ settings
  143. * for keyboard and mouse
  144. */
  145. static inline void __init sio_write(u8 val, u8 index)
  146. {
  147. outb(index, 0x15c);
  148. outb(val, 0x15d);
  149. }
  150. static inline u8 __init sio_read(u8 index)
  151. {
  152. outb(index, 0x15c);
  153. return inb(0x15d);
  154. }
  155. static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
  156. u8 type)
  157. {
  158. u8 level0, type0, active;
  159. /* select logical device */
  160. sio_write(device, 0x07);
  161. active = sio_read(0x30);
  162. level0 = sio_read(0x70);
  163. type0 = sio_read(0x71);
  164. if (level0 != level || type0 != type || !active) {
  165. printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
  166. "remapping to level %d, type %d, active\n",
  167. name, level0, type0, !active ? "in" : "", level, type);
  168. sio_write(0x01, 0x30);
  169. sio_write(level, 0x70);
  170. sio_write(type, 0x71);
  171. }
  172. }
  173. static void __init sio_init(void)
  174. {
  175. struct device_node *root;
  176. const char *model;
  177. root = of_find_node_by_path("/");
  178. if (!root)
  179. return;
  180. model = of_get_property(root, "model", NULL);
  181. if (model && !strncmp(model, "IBM,LongTrail", 13)) {
  182. /* logical device 0 (KBC/Keyboard) */
  183. sio_fixup_irq("keyboard", 0, 1, 2);
  184. /* select logical device 1 (KBC/Mouse) */
  185. sio_fixup_irq("mouse", 1, 12, 2);
  186. }
  187. of_node_put(root);
  188. }
  189. static void __init pegasos_set_l2cr(void)
  190. {
  191. struct device_node *np;
  192. /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
  193. if (_chrp_type != _CHRP_Pegasos)
  194. return;
  195. /* Enable L2 cache if needed */
  196. np = of_find_node_by_type(NULL, "cpu");
  197. if (np != NULL) {
  198. const unsigned int *l2cr = of_get_property(np, "l2cr", NULL);
  199. if (l2cr == NULL) {
  200. printk ("Pegasos l2cr : no cpu l2cr property found\n");
  201. goto out;
  202. }
  203. if (!((*l2cr) & 0x80000000)) {
  204. printk ("Pegasos l2cr : L2 cache was not active, "
  205. "activating\n");
  206. _set_L2CR(0);
  207. _set_L2CR((*l2cr) | 0x80000000);
  208. }
  209. }
  210. out:
  211. of_node_put(np);
  212. }
  213. static void __noreturn briq_restart(char *cmd)
  214. {
  215. local_irq_disable();
  216. if (briq_SPOR)
  217. out_be32(briq_SPOR, 0);
  218. for(;;);
  219. }
  220. /*
  221. * Per default, input/output-device points to the keyboard/screen
  222. * If no card is installed, the built-in serial port is used as a fallback.
  223. * But unfortunately, the firmware does not connect /chosen/{stdin,stdout}
  224. * the the built-in serial node. Instead, a /failsafe node is created.
  225. */
  226. static __init void chrp_init(void)
  227. {
  228. struct device_node *node;
  229. const char *property;
  230. if (strstr(boot_command_line, "console="))
  231. return;
  232. /* find the boot console from /chosen/stdout */
  233. if (!of_chosen)
  234. return;
  235. node = of_find_node_by_path("/");
  236. if (!node)
  237. return;
  238. property = of_get_property(node, "model", NULL);
  239. if (!property)
  240. goto out_put;
  241. if (strcmp(property, "Pegasos2"))
  242. goto out_put;
  243. /* this is a Pegasos2 */
  244. property = of_get_property(of_chosen, "linux,stdout-path", NULL);
  245. if (!property)
  246. goto out_put;
  247. of_node_put(node);
  248. node = of_find_node_by_path(property);
  249. if (!node)
  250. return;
  251. property = of_get_property(node, "device_type", NULL);
  252. if (!property)
  253. goto out_put;
  254. if (strcmp(property, "serial"))
  255. goto out_put;
  256. /*
  257. * The 9pin connector is either /failsafe
  258. * or /pci@80000000/isa@C/serial@i2F8
  259. * The optional graphics card has also type 'serial' in VGA mode.
  260. */
  261. property = of_get_property(node, "name", NULL);
  262. if (!property)
  263. goto out_put;
  264. if (!strcmp(property, "failsafe") || !strcmp(property, "serial"))
  265. add_preferred_console("ttyS", 0, NULL);
  266. out_put:
  267. of_node_put(node);
  268. }
  269. void __init chrp_setup_arch(void)
  270. {
  271. struct device_node *root = of_find_node_by_path("/");
  272. const char *machine = NULL;
  273. /* init to some ~sane value until calibrate_delay() runs */
  274. loops_per_jiffy = 50000000/HZ;
  275. if (root)
  276. machine = of_get_property(root, "model", NULL);
  277. if (machine && strncmp(machine, "Pegasos", 7) == 0) {
  278. _chrp_type = _CHRP_Pegasos;
  279. } else if (machine && strncmp(machine, "IBM", 3) == 0) {
  280. _chrp_type = _CHRP_IBM;
  281. } else if (machine && strncmp(machine, "MOT", 3) == 0) {
  282. _chrp_type = _CHRP_Motorola;
  283. } else if (machine && strncmp(machine, "TotalImpact,BRIQ-1", 18) == 0) {
  284. _chrp_type = _CHRP_briq;
  285. /* Map the SPOR register on briq and change the restart hook */
  286. briq_SPOR = ioremap(0xff0000e8, 4);
  287. ppc_md.restart = briq_restart;
  288. } else {
  289. /* Let's assume it is an IBM chrp if all else fails */
  290. _chrp_type = _CHRP_IBM;
  291. }
  292. of_node_put(root);
  293. printk("chrp type = %x [%s]\n", _chrp_type, chrp_names[_chrp_type]);
  294. rtas_initialize();
  295. if (rtas_token("display-character") >= 0)
  296. ppc_md.progress = rtas_progress;
  297. /* use RTAS time-of-day routines if available */
  298. if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
  299. ppc_md.get_boot_time = rtas_get_boot_time;
  300. ppc_md.get_rtc_time = rtas_get_rtc_time;
  301. ppc_md.set_rtc_time = rtas_set_rtc_time;
  302. }
  303. /* On pegasos, enable the L2 cache if not already done by OF */
  304. pegasos_set_l2cr();
  305. /* Lookup PCI host bridges */
  306. chrp_find_bridges();
  307. /*
  308. * Temporary fixes for PCI devices.
  309. * -- Geert
  310. */
  311. hydra_init(); /* Mac I/O */
  312. /*
  313. * Fix the Super I/O configuration
  314. */
  315. sio_init();
  316. pci_create_OF_bus_map();
  317. /*
  318. * Print the banner, then scroll down so boot progress
  319. * can be printed. -- Cort
  320. */
  321. if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
  322. }
  323. static void chrp_8259_cascade(struct irq_desc *desc)
  324. {
  325. struct irq_chip *chip = irq_desc_get_chip(desc);
  326. unsigned int cascade_irq = i8259_irq();
  327. if (cascade_irq)
  328. generic_handle_irq(cascade_irq);
  329. chip->irq_eoi(&desc->irq_data);
  330. }
  331. /*
  332. * Finds the open-pic node and sets up the mpic driver.
  333. */
  334. static void __init chrp_find_openpic(void)
  335. {
  336. struct device_node *np, *root;
  337. int len, i, j;
  338. int isu_size, idu_size;
  339. const unsigned int *iranges, *opprop = NULL;
  340. int oplen = 0;
  341. unsigned long opaddr;
  342. int na = 1;
  343. np = of_find_node_by_type(NULL, "open-pic");
  344. if (np == NULL)
  345. return;
  346. root = of_find_node_by_path("/");
  347. if (root) {
  348. opprop = of_get_property(root, "platform-open-pic", &oplen);
  349. na = of_n_addr_cells(root);
  350. }
  351. if (opprop && oplen >= na * sizeof(unsigned int)) {
  352. opaddr = opprop[na-1]; /* assume 32-bit */
  353. oplen /= na * sizeof(unsigned int);
  354. } else {
  355. struct resource r;
  356. if (of_address_to_resource(np, 0, &r)) {
  357. goto bail;
  358. }
  359. opaddr = r.start;
  360. oplen = 0;
  361. }
  362. printk(KERN_INFO "OpenPIC at %lx\n", opaddr);
  363. iranges = of_get_property(np, "interrupt-ranges", &len);
  364. if (iranges == NULL)
  365. len = 0; /* non-distributed mpic */
  366. else
  367. len /= 2 * sizeof(unsigned int);
  368. /*
  369. * The first pair of cells in interrupt-ranges refers to the
  370. * IDU; subsequent pairs refer to the ISUs.
  371. */
  372. if (oplen < len) {
  373. printk(KERN_ERR "Insufficient addresses for distributed"
  374. " OpenPIC (%d < %d)\n", oplen, len);
  375. len = oplen;
  376. }
  377. isu_size = 0;
  378. idu_size = 0;
  379. if (len > 0 && iranges[1] != 0) {
  380. printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
  381. iranges[0], iranges[0] + iranges[1] - 1);
  382. idu_size = iranges[1];
  383. }
  384. if (len > 1)
  385. isu_size = iranges[3];
  386. chrp_mpic = mpic_alloc(np, opaddr, MPIC_NO_RESET,
  387. isu_size, 0, " MPIC ");
  388. if (chrp_mpic == NULL) {
  389. printk(KERN_ERR "Failed to allocate MPIC structure\n");
  390. goto bail;
  391. }
  392. j = na - 1;
  393. for (i = 1; i < len; ++i) {
  394. iranges += 2;
  395. j += na;
  396. printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x\n",
  397. iranges[0], iranges[0] + iranges[1] - 1,
  398. opprop[j]);
  399. mpic_assign_isu(chrp_mpic, i - 1, opprop[j]);
  400. }
  401. mpic_init(chrp_mpic);
  402. ppc_md.get_irq = mpic_get_irq;
  403. bail:
  404. of_node_put(root);
  405. of_node_put(np);
  406. }
  407. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)
  408. static struct irqaction xmon_irqaction = {
  409. .handler = xmon_irq,
  410. .name = "XMON break",
  411. };
  412. #endif
  413. static void __init chrp_find_8259(void)
  414. {
  415. struct device_node *np, *pic = NULL;
  416. unsigned long chrp_int_ack = 0;
  417. unsigned int cascade_irq;
  418. /* Look for cascade */
  419. for_each_node_by_type(np, "interrupt-controller")
  420. if (of_device_is_compatible(np, "chrp,iic")) {
  421. pic = np;
  422. break;
  423. }
  424. /* Ok, 8259 wasn't found. We need to handle the case where
  425. * we have a pegasos that claims to be chrp but doesn't have
  426. * a proper interrupt tree
  427. */
  428. if (pic == NULL && chrp_mpic != NULL) {
  429. printk(KERN_ERR "i8259: Not found in device-tree"
  430. " assuming no legacy interrupts\n");
  431. return;
  432. }
  433. /* Look for intack. In a perfect world, we would look for it on
  434. * the ISA bus that holds the 8259 but heh... Works that way. If
  435. * we ever see a problem, we can try to re-use the pSeries code here.
  436. * Also, Pegasos-type platforms don't have a proper node to start
  437. * from anyway
  438. */
  439. for_each_node_by_name(np, "pci") {
  440. const unsigned int *addrp = of_get_property(np,
  441. "8259-interrupt-acknowledge", NULL);
  442. if (addrp == NULL)
  443. continue;
  444. chrp_int_ack = addrp[of_n_addr_cells(np)-1];
  445. break;
  446. }
  447. of_node_put(np);
  448. if (np == NULL)
  449. printk(KERN_WARNING "Cannot find PCI interrupt acknowledge"
  450. " address, polling\n");
  451. i8259_init(pic, chrp_int_ack);
  452. if (ppc_md.get_irq == NULL) {
  453. ppc_md.get_irq = i8259_irq;
  454. irq_set_default_host(i8259_get_host());
  455. }
  456. if (chrp_mpic != NULL) {
  457. cascade_irq = irq_of_parse_and_map(pic, 0);
  458. if (!cascade_irq)
  459. printk(KERN_ERR "i8259: failed to map cascade irq\n");
  460. else
  461. irq_set_chained_handler(cascade_irq,
  462. chrp_8259_cascade);
  463. }
  464. }
  465. void __init chrp_init_IRQ(void)
  466. {
  467. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)
  468. struct device_node *kbd;
  469. #endif
  470. chrp_find_openpic();
  471. chrp_find_8259();
  472. #ifdef CONFIG_SMP
  473. /* Pegasos has no MPIC, those ops would make it crash. It might be an
  474. * option to move setting them to after we probe the PIC though
  475. */
  476. if (chrp_mpic != NULL)
  477. smp_ops = &chrp_smp_ops;
  478. #endif /* CONFIG_SMP */
  479. if (_chrp_type == _CHRP_Pegasos)
  480. ppc_md.get_irq = i8259_irq;
  481. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_XMON)
  482. /* see if there is a keyboard in the device tree
  483. with a parent of type "adb" */
  484. for_each_node_by_name(kbd, "keyboard")
  485. if (kbd->parent && kbd->parent->type
  486. && strcmp(kbd->parent->type, "adb") == 0)
  487. break;
  488. of_node_put(kbd);
  489. if (kbd)
  490. setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
  491. #endif
  492. }
  493. void __init
  494. chrp_init2(void)
  495. {
  496. #ifdef CONFIG_NVRAM
  497. chrp_nvram_init();
  498. #endif
  499. request_region(0x20,0x20,"pic1");
  500. request_region(0xa0,0x20,"pic2");
  501. request_region(0x00,0x20,"dma1");
  502. request_region(0x40,0x20,"timer");
  503. request_region(0x80,0x10,"dma page reg");
  504. request_region(0xc0,0x20,"dma2");
  505. if (ppc_md.progress)
  506. ppc_md.progress(" Have fun! ", 0x7777);
  507. }
  508. static int __init chrp_probe(void)
  509. {
  510. const char *dtype = of_get_flat_dt_prop(of_get_flat_dt_root(),
  511. "device_type", NULL);
  512. if (dtype == NULL)
  513. return 0;
  514. if (strcmp(dtype, "chrp"))
  515. return 0;
  516. ISA_DMA_THRESHOLD = ~0L;
  517. DMA_MODE_READ = 0x44;
  518. DMA_MODE_WRITE = 0x48;
  519. pm_power_off = rtas_power_off;
  520. chrp_init();
  521. return 1;
  522. }
  523. define_machine(chrp) {
  524. .name = "CHRP",
  525. .probe = chrp_probe,
  526. .setup_arch = chrp_setup_arch,
  527. .init = chrp_init2,
  528. .show_cpuinfo = chrp_show_cpuinfo,
  529. .init_IRQ = chrp_init_IRQ,
  530. .restart = rtas_restart,
  531. .halt = rtas_halt,
  532. .time_init = chrp_time_init,
  533. .set_rtc_time = chrp_set_rtc_time,
  534. .get_rtc_time = chrp_get_rtc_time,
  535. .calibrate_decr = generic_calibrate_decr,
  536. .phys_mem_access_prot = pci_phys_mem_access_prot,
  537. };