setup.c 15 KB

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