setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. /*
  258. * Print the banner, then scroll down so boot progress
  259. * can be printed. -- Cort
  260. */
  261. if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
  262. }
  263. void
  264. chrp_event_scan(unsigned long unused)
  265. {
  266. unsigned char log[1024];
  267. int ret = 0;
  268. /* XXX: we should loop until the hardware says no more error logs -- Cort */
  269. rtas_call(rtas_token("event-scan"), 4, 1, &ret, 0xffffffff, 0,
  270. __pa(log), 1024);
  271. mod_timer(&__get_cpu_var(heartbeat_timer),
  272. jiffies + event_scan_interval);
  273. }
  274. /*
  275. * Finds the open-pic node and sets up the mpic driver.
  276. */
  277. static void __init chrp_find_openpic(void)
  278. {
  279. struct device_node *np, *root;
  280. int len, i, j, irq_count;
  281. int isu_size, idu_size;
  282. unsigned int *iranges, *opprop = NULL;
  283. int oplen = 0;
  284. unsigned long opaddr;
  285. int na = 1;
  286. unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
  287. np = find_type_devices("open-pic");
  288. if (np == NULL)
  289. return;
  290. root = find_path_device("/");
  291. if (root) {
  292. opprop = (unsigned int *) get_property
  293. (root, "platform-open-pic", &oplen);
  294. na = prom_n_addr_cells(root);
  295. }
  296. if (opprop && oplen >= na * sizeof(unsigned int)) {
  297. opaddr = opprop[na-1]; /* assume 32-bit */
  298. oplen /= na * sizeof(unsigned int);
  299. } else {
  300. struct resource r;
  301. if (of_address_to_resource(np, 0, &r))
  302. return;
  303. opaddr = r.start;
  304. oplen = 0;
  305. }
  306. printk(KERN_INFO "OpenPIC at %lx\n", opaddr);
  307. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  308. prom_get_irq_senses(init_senses, NUM_ISA_INTERRUPTS, NR_IRQS - 4);
  309. /* i8259 cascade is always positive level */
  310. init_senses[0] = IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE;
  311. iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
  312. if (iranges == NULL)
  313. len = 0; /* non-distributed mpic */
  314. else
  315. len /= 2 * sizeof(unsigned int);
  316. /*
  317. * The first pair of cells in interrupt-ranges refers to the
  318. * IDU; subsequent pairs refer to the ISUs.
  319. */
  320. if (oplen < len) {
  321. printk(KERN_ERR "Insufficient addresses for distributed"
  322. " OpenPIC (%d < %d)\n", oplen, len);
  323. len = oplen;
  324. }
  325. isu_size = 0;
  326. idu_size = 0;
  327. if (len > 0 && iranges[1] != 0) {
  328. printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
  329. iranges[0], iranges[0] + iranges[1] - 1);
  330. idu_size = iranges[1];
  331. }
  332. if (len > 1)
  333. isu_size = iranges[3];
  334. chrp_mpic = mpic_alloc(opaddr, MPIC_PRIMARY,
  335. isu_size, NUM_ISA_INTERRUPTS, irq_count,
  336. NR_IRQS - 4, init_senses, irq_count,
  337. " MPIC ");
  338. if (chrp_mpic == NULL) {
  339. printk(KERN_ERR "Failed to allocate MPIC structure\n");
  340. return;
  341. }
  342. j = na - 1;
  343. for (i = 1; i < len; ++i) {
  344. iranges += 2;
  345. j += na;
  346. printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x\n",
  347. iranges[0], iranges[0] + iranges[1] - 1,
  348. opprop[j]);
  349. mpic_assign_isu(chrp_mpic, i - 1, opprop[j]);
  350. }
  351. mpic_init(chrp_mpic);
  352. mpic_setup_cascade(NUM_ISA_INTERRUPTS, i8259_irq_cascade, NULL);
  353. }
  354. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  355. static struct irqaction xmon_irqaction = {
  356. .handler = xmon_irq,
  357. .mask = CPU_MASK_NONE,
  358. .name = "XMON break",
  359. };
  360. #endif
  361. void __init chrp_init_IRQ(void)
  362. {
  363. struct device_node *np;
  364. unsigned long chrp_int_ack = 0;
  365. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  366. struct device_node *kbd;
  367. #endif
  368. for (np = find_devices("pci"); np != NULL; np = np->next) {
  369. unsigned int *addrp = (unsigned int *)
  370. get_property(np, "8259-interrupt-acknowledge", NULL);
  371. if (addrp == NULL)
  372. continue;
  373. chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
  374. break;
  375. }
  376. if (np == NULL)
  377. printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
  378. chrp_find_openpic();
  379. i8259_init(chrp_int_ack, 0);
  380. if (_chrp_type == _CHRP_Pegasos)
  381. ppc_md.get_irq = i8259_irq;
  382. else
  383. ppc_md.get_irq = mpic_get_irq;
  384. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  385. /* see if there is a keyboard in the device tree
  386. with a parent of type "adb" */
  387. for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
  388. if (kbd->parent && kbd->parent->type
  389. && strcmp(kbd->parent->type, "adb") == 0)
  390. break;
  391. if (kbd)
  392. setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
  393. #endif
  394. }
  395. void __init
  396. chrp_init2(void)
  397. {
  398. struct device_node *device;
  399. unsigned int *p = NULL;
  400. #ifdef CONFIG_NVRAM
  401. chrp_nvram_init();
  402. #endif
  403. request_region(0x20,0x20,"pic1");
  404. request_region(0xa0,0x20,"pic2");
  405. request_region(0x00,0x20,"dma1");
  406. request_region(0x40,0x20,"timer");
  407. request_region(0x80,0x10,"dma page reg");
  408. request_region(0xc0,0x20,"dma2");
  409. /* Get the event scan rate for the rtas so we know how
  410. * often it expects a heartbeat. -- Cort
  411. */
  412. device = find_devices("rtas");
  413. if (device)
  414. p = (unsigned int *) get_property
  415. (device, "rtas-event-scan-rate", NULL);
  416. if (p && *p) {
  417. /*
  418. * Arrange to call chrp_event_scan at least *p times
  419. * per minute. We use 59 rather than 60 here so that
  420. * the rate will be slightly higher than the minimum.
  421. * This all assumes we don't do hotplug CPU on any
  422. * machine that needs the event scans done.
  423. */
  424. unsigned long interval, offset;
  425. int cpu, ncpus;
  426. struct timer_list *timer;
  427. interval = HZ * 59 / *p;
  428. offset = HZ;
  429. ncpus = num_online_cpus();
  430. event_scan_interval = ncpus * interval;
  431. for (cpu = 0; cpu < ncpus; ++cpu) {
  432. timer = &per_cpu(heartbeat_timer, cpu);
  433. setup_timer(timer, chrp_event_scan, 0);
  434. timer->expires = jiffies + offset;
  435. add_timer_on(timer, cpu);
  436. offset += interval;
  437. }
  438. printk("RTAS Event Scan Rate: %u (%lu jiffies)\n",
  439. *p, interval);
  440. }
  441. if (ppc_md.progress)
  442. ppc_md.progress(" Have fun! ", 0x7777);
  443. }
  444. void __init chrp_init(void)
  445. {
  446. ISA_DMA_THRESHOLD = ~0L;
  447. DMA_MODE_READ = 0x44;
  448. DMA_MODE_WRITE = 0x48;
  449. isa_io_base = CHRP_ISA_IO_BASE; /* default value */
  450. ppc_do_canonicalize_irqs = 1;
  451. /* Assume we have an 8259... */
  452. __irq_offset_value = NUM_ISA_INTERRUPTS;
  453. ppc_md.setup_arch = chrp_setup_arch;
  454. ppc_md.show_cpuinfo = chrp_show_cpuinfo;
  455. ppc_md.init_IRQ = chrp_init_IRQ;
  456. ppc_md.init = chrp_init2;
  457. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  458. ppc_md.restart = rtas_restart;
  459. ppc_md.power_off = rtas_power_off;
  460. ppc_md.halt = rtas_halt;
  461. ppc_md.time_init = chrp_time_init;
  462. ppc_md.calibrate_decr = generic_calibrate_decr;
  463. /* this may get overridden with rtas routines later... */
  464. ppc_md.set_rtc_time = chrp_set_rtc_time;
  465. ppc_md.get_rtc_time = chrp_get_rtc_time;
  466. #ifdef CONFIG_SMP
  467. smp_ops = &chrp_smp_ops;
  468. #endif /* CONFIG_SMP */
  469. }