setup.c 14 KB

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