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