setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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/config.h>
  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/slab.h>
  18. #include <linux/user.h>
  19. #include <linux/a.out.h>
  20. #include <linux/tty.h>
  21. #include <linux/major.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/reboot.h>
  24. #include <linux/init.h>
  25. #include <linux/pci.h>
  26. #include <linux/version.h>
  27. #include <linux/adb.h>
  28. #include <linux/module.h>
  29. #include <linux/delay.h>
  30. #include <linux/ide.h>
  31. #include <linux/console.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/root_dev.h>
  34. #include <linux/initrd.h>
  35. #include <linux/module.h>
  36. #include <linux/timer.h>
  37. #include <asm/io.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/prom.h>
  40. #include <asm/gg2.h>
  41. #include <asm/pci-bridge.h>
  42. #include <asm/dma.h>
  43. #include <asm/machdep.h>
  44. #include <asm/irq.h>
  45. #include <asm/hydra.h>
  46. #include <asm/sections.h>
  47. #include <asm/time.h>
  48. #include <asm/i8259.h>
  49. #include <asm/mpic.h>
  50. #include <asm/rtas.h>
  51. #include <asm/xmon.h>
  52. #include "chrp.h"
  53. void rtas_indicator_progress(char *, unsigned short);
  54. int _chrp_type;
  55. EXPORT_SYMBOL(_chrp_type);
  56. struct mpic *chrp_mpic;
  57. /* Used for doing CHRP event-scans */
  58. DEFINE_PER_CPU(struct timer_list, heartbeat_timer);
  59. unsigned long event_scan_interval;
  60. /*
  61. * XXX this should be in xmon.h, but putting it there means xmon.h
  62. * has to include <linux/interrupt.h> (to get irqreturn_t), which
  63. * causes all sorts of problems. -- paulus
  64. */
  65. extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
  66. extern unsigned long loops_per_jiffy;
  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. void chrp_show_cpuinfo(struct seq_file *m)
  84. {
  85. int i, sdramen;
  86. unsigned int t;
  87. struct device_node *root;
  88. const char *model = "";
  89. root = find_path_device("/");
  90. if (root)
  91. model = get_property(root, "model", NULL);
  92. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  93. /* longtrail (goldengate) stuff */
  94. if (!strncmp(model, "IBM,LongTrail", 13)) {
  95. /* VLSI VAS96011/12 `Golden Gate 2' */
  96. /* Memory banks */
  97. sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
  98. >>31) & 1;
  99. for (i = 0; i < (sdramen ? 4 : 6); i++) {
  100. t = in_le32(gg2_pci_config_base+
  101. GG2_PCI_DRAM_BANK0+
  102. i*4);
  103. if (!(t & 1))
  104. continue;
  105. switch ((t>>8) & 0x1f) {
  106. case 0x1f:
  107. model = "4 MB";
  108. break;
  109. case 0x1e:
  110. model = "8 MB";
  111. break;
  112. case 0x1c:
  113. model = "16 MB";
  114. break;
  115. case 0x18:
  116. model = "32 MB";
  117. break;
  118. case 0x10:
  119. model = "64 MB";
  120. break;
  121. case 0x00:
  122. model = "128 MB";
  123. break;
  124. default:
  125. model = "Reserved";
  126. break;
  127. }
  128. seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
  129. gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
  130. }
  131. /* L2 cache */
  132. t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
  133. seq_printf(m, "board l2\t: %s %s (%s)\n",
  134. gg2_cachesizes[(t>>7) & 3],
  135. gg2_cachetypes[(t>>2) & 3],
  136. gg2_cachemodes[t & 3]);
  137. }
  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. if ((root = find_path_device("/")) &&
  177. !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
  178. /* logical device 0 (KBC/Keyboard) */
  179. sio_fixup_irq("keyboard", 0, 1, 2);
  180. /* select logical device 1 (KBC/Mouse) */
  181. sio_fixup_irq("mouse", 1, 12, 2);
  182. }
  183. }
  184. static void __init pegasos_set_l2cr(void)
  185. {
  186. struct device_node *np;
  187. /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
  188. if (_chrp_type != _CHRP_Pegasos)
  189. return;
  190. /* Enable L2 cache if needed */
  191. np = find_type_devices("cpu");
  192. if (np != NULL) {
  193. unsigned int *l2cr = (unsigned int *)
  194. get_property (np, "l2cr", NULL);
  195. if (l2cr == NULL) {
  196. printk ("Pegasos l2cr : no cpu l2cr property found\n");
  197. return;
  198. }
  199. if (!((*l2cr) & 0x80000000)) {
  200. printk ("Pegasos l2cr : L2 cache was not active, "
  201. "activating\n");
  202. _set_L2CR(0);
  203. _set_L2CR((*l2cr) | 0x80000000);
  204. }
  205. }
  206. }
  207. void __init chrp_setup_arch(void)
  208. {
  209. struct device_node *root = find_path_device ("/");
  210. char *machine = NULL;
  211. /* init to some ~sane value until calibrate_delay() runs */
  212. loops_per_jiffy = 50000000/HZ;
  213. if (root)
  214. machine = get_property(root, "model", NULL);
  215. if (machine && strncmp(machine, "Pegasos", 7) == 0) {
  216. _chrp_type = _CHRP_Pegasos;
  217. } else if (machine && strncmp(machine, "IBM", 3) == 0) {
  218. _chrp_type = _CHRP_IBM;
  219. } else if (machine && strncmp(machine, "MOT", 3) == 0) {
  220. _chrp_type = _CHRP_Motorola;
  221. } else {
  222. /* Let's assume it is an IBM chrp if all else fails */
  223. _chrp_type = _CHRP_IBM;
  224. }
  225. printk("chrp type = %x\n", _chrp_type);
  226. rtas_initialize();
  227. if (rtas_token("display-character") >= 0)
  228. ppc_md.progress = rtas_progress;
  229. /* use RTAS time-of-day routines if available */
  230. if (rtas_token("get-time-of-day") != RTAS_UNKNOWN_SERVICE) {
  231. ppc_md.get_boot_time = rtas_get_boot_time;
  232. ppc_md.get_rtc_time = rtas_get_rtc_time;
  233. ppc_md.set_rtc_time = rtas_set_rtc_time;
  234. }
  235. #ifdef CONFIG_BLK_DEV_INITRD
  236. /* this is fine for chrp */
  237. initrd_below_start_ok = 1;
  238. if (initrd_start)
  239. ROOT_DEV = Root_RAM0;
  240. else
  241. #endif
  242. ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
  243. /* On pegasos, enable the L2 cache if not already done by OF */
  244. pegasos_set_l2cr();
  245. /* Lookup PCI host bridges */
  246. chrp_find_bridges();
  247. /*
  248. * Temporary fixes for PCI devices.
  249. * -- Geert
  250. */
  251. hydra_init(); /* Mac I/O */
  252. /*
  253. * Fix the Super I/O configuration
  254. */
  255. sio_init();
  256. pci_create_OF_bus_map();
  257. #ifdef CONFIG_SMP
  258. smp_ops = &chrp_smp_ops;
  259. #endif /* CONFIG_SMP */
  260. /*
  261. * Print the banner, then scroll down so boot progress
  262. * can be printed. -- Cort
  263. */
  264. if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
  265. }
  266. void
  267. chrp_event_scan(unsigned long unused)
  268. {
  269. unsigned char log[1024];
  270. int ret = 0;
  271. /* XXX: we should loop until the hardware says no more error logs -- Cort */
  272. rtas_call(rtas_token("event-scan"), 4, 1, &ret, 0xffffffff, 0,
  273. __pa(log), 1024);
  274. mod_timer(&__get_cpu_var(heartbeat_timer),
  275. jiffies + event_scan_interval);
  276. }
  277. /*
  278. * Finds the open-pic node and sets up the mpic driver.
  279. */
  280. static void __init chrp_find_openpic(void)
  281. {
  282. struct device_node *np, *root;
  283. int len, i, j, irq_count;
  284. int isu_size, idu_size;
  285. unsigned int *iranges, *opprop = NULL;
  286. int oplen = 0;
  287. unsigned long opaddr;
  288. int na = 1;
  289. unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
  290. np = find_type_devices("open-pic");
  291. if (np == NULL)
  292. return;
  293. root = find_path_device("/");
  294. if (root) {
  295. opprop = (unsigned int *) get_property
  296. (root, "platform-open-pic", &oplen);
  297. na = prom_n_addr_cells(root);
  298. }
  299. if (opprop && oplen >= na * sizeof(unsigned int)) {
  300. opaddr = opprop[na-1]; /* assume 32-bit */
  301. oplen /= na * sizeof(unsigned int);
  302. } else {
  303. struct resource r;
  304. if (of_address_to_resource(np, 0, &r))
  305. return;
  306. opaddr = r.start;
  307. oplen = 0;
  308. }
  309. printk(KERN_INFO "OpenPIC at %lx\n", opaddr);
  310. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  311. prom_get_irq_senses(init_senses, NUM_ISA_INTERRUPTS, NR_IRQS - 4);
  312. /* i8259 cascade is always positive level */
  313. init_senses[0] = IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE;
  314. iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
  315. if (iranges == NULL)
  316. len = 0; /* non-distributed mpic */
  317. else
  318. len /= 2 * sizeof(unsigned int);
  319. /*
  320. * The first pair of cells in interrupt-ranges refers to the
  321. * IDU; subsequent pairs refer to the ISUs.
  322. */
  323. if (oplen < len) {
  324. printk(KERN_ERR "Insufficient addresses for distributed"
  325. " OpenPIC (%d < %d)\n", oplen, len);
  326. len = oplen;
  327. }
  328. isu_size = 0;
  329. idu_size = 0;
  330. if (len > 0 && iranges[1] != 0) {
  331. printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
  332. iranges[0], iranges[0] + iranges[1] - 1);
  333. idu_size = iranges[1];
  334. }
  335. if (len > 1)
  336. isu_size = iranges[3];
  337. chrp_mpic = mpic_alloc(opaddr, MPIC_PRIMARY,
  338. isu_size, NUM_ISA_INTERRUPTS, irq_count,
  339. NR_IRQS - 4, init_senses, irq_count,
  340. " MPIC ");
  341. if (chrp_mpic == NULL) {
  342. printk(KERN_ERR "Failed to allocate MPIC structure\n");
  343. return;
  344. }
  345. j = na - 1;
  346. for (i = 1; i < len; ++i) {
  347. iranges += 2;
  348. j += na;
  349. printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x\n",
  350. iranges[0], iranges[0] + iranges[1] - 1,
  351. opprop[j]);
  352. mpic_assign_isu(chrp_mpic, i - 1, opprop[j]);
  353. }
  354. mpic_init(chrp_mpic);
  355. mpic_setup_cascade(NUM_ISA_INTERRUPTS, i8259_irq_cascade, NULL);
  356. }
  357. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  358. static struct irqaction xmon_irqaction = {
  359. .handler = xmon_irq,
  360. .mask = CPU_MASK_NONE,
  361. .name = "XMON break",
  362. };
  363. #endif
  364. void __init chrp_init_IRQ(void)
  365. {
  366. struct device_node *np;
  367. unsigned long chrp_int_ack = 0;
  368. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  369. struct device_node *kbd;
  370. #endif
  371. for (np = find_devices("pci"); np != NULL; np = np->next) {
  372. unsigned int *addrp = (unsigned int *)
  373. get_property(np, "8259-interrupt-acknowledge", NULL);
  374. if (addrp == NULL)
  375. continue;
  376. chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
  377. break;
  378. }
  379. if (np == NULL)
  380. printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
  381. chrp_find_openpic();
  382. i8259_init(chrp_int_ack, 0);
  383. if (_chrp_type == _CHRP_Pegasos)
  384. ppc_md.get_irq = i8259_irq;
  385. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  386. /* see if there is a keyboard in the device tree
  387. with a parent of type "adb" */
  388. for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
  389. if (kbd->parent && kbd->parent->type
  390. && strcmp(kbd->parent->type, "adb") == 0)
  391. break;
  392. if (kbd)
  393. setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
  394. #endif
  395. }
  396. void __init
  397. chrp_init2(void)
  398. {
  399. struct device_node *device;
  400. unsigned int *p = NULL;
  401. #ifdef CONFIG_NVRAM
  402. chrp_nvram_init();
  403. #endif
  404. request_region(0x20,0x20,"pic1");
  405. request_region(0xa0,0x20,"pic2");
  406. request_region(0x00,0x20,"dma1");
  407. request_region(0x40,0x20,"timer");
  408. request_region(0x80,0x10,"dma page reg");
  409. request_region(0xc0,0x20,"dma2");
  410. /* Get the event scan rate for the rtas so we know how
  411. * often it expects a heartbeat. -- Cort
  412. */
  413. device = find_devices("rtas");
  414. if (device)
  415. p = (unsigned int *) get_property
  416. (device, "rtas-event-scan-rate", NULL);
  417. if (p && *p) {
  418. /*
  419. * Arrange to call chrp_event_scan at least *p times
  420. * per minute. We use 59 rather than 60 here so that
  421. * the rate will be slightly higher than the minimum.
  422. * This all assumes we don't do hotplug CPU on any
  423. * machine that needs the event scans done.
  424. */
  425. unsigned long interval, offset;
  426. int cpu, ncpus;
  427. struct timer_list *timer;
  428. interval = HZ * 59 / *p;
  429. offset = HZ;
  430. ncpus = num_online_cpus();
  431. event_scan_interval = ncpus * interval;
  432. for (cpu = 0; cpu < ncpus; ++cpu) {
  433. timer = &per_cpu(heartbeat_timer, cpu);
  434. setup_timer(timer, chrp_event_scan, 0);
  435. timer->expires = jiffies + offset;
  436. add_timer_on(timer, cpu);
  437. offset += interval;
  438. }
  439. printk("RTAS Event Scan Rate: %u (%lu jiffies)\n",
  440. *p, interval);
  441. }
  442. if (ppc_md.progress)
  443. ppc_md.progress(" Have fun! ", 0x7777);
  444. }
  445. static int __init chrp_probe(void)
  446. {
  447. char *dtype = of_get_flat_dt_prop(of_get_flat_dt_root(),
  448. "device_type", NULL);
  449. if (dtype == NULL)
  450. return 0;
  451. if (strcmp(dtype, "chrp"))
  452. return 0;
  453. ISA_DMA_THRESHOLD = ~0L;
  454. DMA_MODE_READ = 0x44;
  455. DMA_MODE_WRITE = 0x48;
  456. isa_io_base = CHRP_ISA_IO_BASE; /* default value */
  457. ppc_do_canonicalize_irqs = 1;
  458. /* Assume we have an 8259... */
  459. __irq_offset_value = NUM_ISA_INTERRUPTS;
  460. return 1;
  461. }
  462. define_machine(chrp) {
  463. .name = "CHRP",
  464. .probe = chrp_probe,
  465. .setup_arch = chrp_setup_arch,
  466. .init = chrp_init2,
  467. .show_cpuinfo = chrp_show_cpuinfo,
  468. .init_IRQ = chrp_init_IRQ,
  469. .get_irq = mpic_get_irq,
  470. .pcibios_fixup = chrp_pcibios_fixup,
  471. .restart = rtas_restart,
  472. .power_off = rtas_power_off,
  473. .halt = rtas_halt,
  474. .time_init = chrp_time_init,
  475. .set_rtc_time = chrp_set_rtc_time,
  476. .get_rtc_time = chrp_get_rtc_time,
  477. .calibrate_decr = generic_calibrate_decr,
  478. .phys_mem_access_prot = pci_phys_mem_access_prot,
  479. };