setup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*
  2. * arch/ppc/platforms/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Adapted from 'alpha' version by Gary Thomas
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. */
  8. /*
  9. * bootup setup stuff..
  10. */
  11. #include <linux/config.h>
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/stddef.h>
  17. #include <linux/unistd.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/slab.h>
  20. #include <linux/user.h>
  21. #include <linux/a.out.h>
  22. #include <linux/tty.h>
  23. #include <linux/major.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/reboot.h>
  26. #include <linux/init.h>
  27. #include <linux/pci.h>
  28. #include <linux/version.h>
  29. #include <linux/adb.h>
  30. #include <linux/module.h>
  31. #include <linux/delay.h>
  32. #include <linux/ide.h>
  33. #include <linux/console.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/root_dev.h>
  36. #include <linux/initrd.h>
  37. #include <linux/module.h>
  38. #include <asm/io.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/prom.h>
  41. #include <asm/gg2.h>
  42. #include <asm/pci-bridge.h>
  43. #include <asm/dma.h>
  44. #include <asm/machdep.h>
  45. #include <asm/irq.h>
  46. #include <asm/hydra.h>
  47. #include <asm/sections.h>
  48. #include <asm/time.h>
  49. #include <asm/i8259.h>
  50. #include <asm/mpic.h>
  51. #include <asm/rtas.h>
  52. #include <asm/xmon.h>
  53. #include "chrp.h"
  54. void rtas_indicator_progress(char *, unsigned short);
  55. int _chrp_type;
  56. EXPORT_SYMBOL(_chrp_type);
  57. struct mpic *chrp_mpic;
  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 *, struct pt_regs *);
  64. extern unsigned long loops_per_jiffy;
  65. #ifdef CONFIG_SMP
  66. extern struct smp_ops_t chrp_smp_ops;
  67. #endif
  68. static const char *gg2_memtypes[4] = {
  69. "FPM", "SDRAM", "EDO", "BEDO"
  70. };
  71. static const char *gg2_cachesizes[4] = {
  72. "256 KB", "512 KB", "1 MB", "Reserved"
  73. };
  74. static const char *gg2_cachetypes[4] = {
  75. "Asynchronous", "Reserved", "Flow-Through Synchronous",
  76. "Pipelined Synchronous"
  77. };
  78. static const char *gg2_cachemodes[4] = {
  79. "Disabled", "Write-Through", "Copy-Back", "Transparent Mode"
  80. };
  81. void chrp_show_cpuinfo(struct seq_file *m)
  82. {
  83. int i, sdramen;
  84. unsigned int t;
  85. struct device_node *root;
  86. const char *model = "";
  87. root = find_path_device("/");
  88. if (root)
  89. model = get_property(root, "model", NULL);
  90. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  91. /* longtrail (goldengate) stuff */
  92. if (!strncmp(model, "IBM,LongTrail", 13)) {
  93. /* VLSI VAS96011/12 `Golden Gate 2' */
  94. /* Memory banks */
  95. sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
  96. >>31) & 1;
  97. for (i = 0; i < (sdramen ? 4 : 6); i++) {
  98. t = in_le32(gg2_pci_config_base+
  99. GG2_PCI_DRAM_BANK0+
  100. i*4);
  101. if (!(t & 1))
  102. continue;
  103. switch ((t>>8) & 0x1f) {
  104. case 0x1f:
  105. model = "4 MB";
  106. break;
  107. case 0x1e:
  108. model = "8 MB";
  109. break;
  110. case 0x1c:
  111. model = "16 MB";
  112. break;
  113. case 0x18:
  114. model = "32 MB";
  115. break;
  116. case 0x10:
  117. model = "64 MB";
  118. break;
  119. case 0x00:
  120. model = "128 MB";
  121. break;
  122. default:
  123. model = "Reserved";
  124. break;
  125. }
  126. seq_printf(m, "memory bank %d\t: %s %s\n", i, model,
  127. gg2_memtypes[sdramen ? 1 : ((t>>1) & 3)]);
  128. }
  129. /* L2 cache */
  130. t = in_le32(gg2_pci_config_base+GG2_PCI_CC_CTRL);
  131. seq_printf(m, "board l2\t: %s %s (%s)\n",
  132. gg2_cachesizes[(t>>7) & 3],
  133. gg2_cachetypes[(t>>2) & 3],
  134. gg2_cachemodes[t & 3]);
  135. }
  136. }
  137. /*
  138. * Fixes for the National Semiconductor PC78308VUL SuperI/O
  139. *
  140. * Some versions of Open Firmware incorrectly initialize the IRQ settings
  141. * for keyboard and mouse
  142. */
  143. static inline void __init sio_write(u8 val, u8 index)
  144. {
  145. outb(index, 0x15c);
  146. outb(val, 0x15d);
  147. }
  148. static inline u8 __init sio_read(u8 index)
  149. {
  150. outb(index, 0x15c);
  151. return inb(0x15d);
  152. }
  153. static void __init sio_fixup_irq(const char *name, u8 device, u8 level,
  154. u8 type)
  155. {
  156. u8 level0, type0, active;
  157. /* select logical device */
  158. sio_write(device, 0x07);
  159. active = sio_read(0x30);
  160. level0 = sio_read(0x70);
  161. type0 = sio_read(0x71);
  162. if (level0 != level || type0 != type || !active) {
  163. printk(KERN_WARNING "sio: %s irq level %d, type %d, %sactive: "
  164. "remapping to level %d, type %d, active\n",
  165. name, level0, type0, !active ? "in" : "", level, type);
  166. sio_write(0x01, 0x30);
  167. sio_write(level, 0x70);
  168. sio_write(type, 0x71);
  169. }
  170. }
  171. static void __init sio_init(void)
  172. {
  173. struct device_node *root;
  174. if ((root = find_path_device("/")) &&
  175. !strncmp(get_property(root, "model", NULL), "IBM,LongTrail", 13)) {
  176. /* logical device 0 (KBC/Keyboard) */
  177. sio_fixup_irq("keyboard", 0, 1, 2);
  178. /* select logical device 1 (KBC/Mouse) */
  179. sio_fixup_irq("mouse", 1, 12, 2);
  180. }
  181. }
  182. static void __init pegasos_set_l2cr(void)
  183. {
  184. struct device_node *np;
  185. /* On Pegasos, enable the l2 cache if needed, as the OF forgets it */
  186. if (_chrp_type != _CHRP_Pegasos)
  187. return;
  188. /* Enable L2 cache if needed */
  189. np = find_type_devices("cpu");
  190. if (np != NULL) {
  191. unsigned int *l2cr = (unsigned int *)
  192. get_property (np, "l2cr", NULL);
  193. if (l2cr == NULL) {
  194. printk ("Pegasos l2cr : no cpu l2cr property found\n");
  195. return;
  196. }
  197. if (!((*l2cr) & 0x80000000)) {
  198. printk ("Pegasos l2cr : L2 cache was not active, "
  199. "activating\n");
  200. _set_L2CR(0);
  201. _set_L2CR((*l2cr) | 0x80000000);
  202. }
  203. }
  204. }
  205. void __init chrp_setup_arch(void)
  206. {
  207. struct device_node *root = find_path_device ("/");
  208. char *machine = NULL;
  209. struct device_node *device;
  210. unsigned int *p = 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. /* Get the event scan rate for the rtas so we know how
  257. * often it expects a heartbeat. -- Cort
  258. */
  259. device = find_devices("rtas");
  260. if (device)
  261. p = (unsigned int *) get_property
  262. (device, "rtas-event-scan-rate", NULL);
  263. if (p && *p) {
  264. ppc_md.heartbeat = chrp_event_scan;
  265. ppc_md.heartbeat_reset = HZ / (*p * 30) - 1;
  266. ppc_md.heartbeat_count = 1;
  267. printk("RTAS Event Scan Rate: %u (%lu jiffies)\n",
  268. *p, ppc_md.heartbeat_reset);
  269. }
  270. pci_create_OF_bus_map();
  271. /*
  272. * Print the banner, then scroll down so boot progress
  273. * can be printed. -- Cort
  274. */
  275. if (ppc_md.progress) ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0x0);
  276. }
  277. void
  278. chrp_event_scan(void)
  279. {
  280. unsigned char log[1024];
  281. int ret = 0;
  282. /* XXX: we should loop until the hardware says no more error logs -- Cort */
  283. rtas_call(rtas_token("event-scan"), 4, 1, &ret, 0xffffffff, 0,
  284. __pa(log), 1024);
  285. ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
  286. }
  287. /*
  288. * Finds the open-pic node and sets up the mpic driver.
  289. */
  290. static void __init chrp_find_openpic(void)
  291. {
  292. struct device_node *np, *root;
  293. int len, i, j, irq_count;
  294. int isu_size, idu_size;
  295. unsigned int *iranges, *opprop = NULL;
  296. int oplen = 0;
  297. unsigned long opaddr;
  298. int na = 1;
  299. unsigned char init_senses[NR_IRQS - NUM_8259_INTERRUPTS];
  300. np = find_type_devices("open-pic");
  301. if (np == NULL)
  302. return;
  303. root = find_path_device("/");
  304. if (root) {
  305. opprop = (unsigned int *) get_property
  306. (root, "platform-open-pic", &oplen);
  307. na = prom_n_addr_cells(root);
  308. }
  309. if (opprop && oplen >= na * sizeof(unsigned int)) {
  310. opaddr = opprop[na-1]; /* assume 32-bit */
  311. oplen /= na * sizeof(unsigned int);
  312. } else {
  313. struct resource r;
  314. if (of_address_to_resource(np, 0, &r))
  315. return;
  316. opaddr = r.start;
  317. oplen = 0;
  318. }
  319. printk(KERN_INFO "OpenPIC at %lx\n", opaddr);
  320. irq_count = NR_IRQS - NUM_ISA_INTERRUPTS - 4; /* leave room for IPIs */
  321. prom_get_irq_senses(init_senses, NUM_ISA_INTERRUPTS, NR_IRQS - 4);
  322. /* i8259 cascade is always positive level */
  323. init_senses[0] = IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE;
  324. iranges = (unsigned int *) get_property(np, "interrupt-ranges", &len);
  325. if (iranges == NULL)
  326. len = 0; /* non-distributed mpic */
  327. else
  328. len /= 2 * sizeof(unsigned int);
  329. /*
  330. * The first pair of cells in interrupt-ranges refers to the
  331. * IDU; subsequent pairs refer to the ISUs.
  332. */
  333. if (oplen < len) {
  334. printk(KERN_ERR "Insufficient addresses for distributed"
  335. " OpenPIC (%d < %d)\n", oplen, len);
  336. len = oplen;
  337. }
  338. isu_size = 0;
  339. idu_size = 0;
  340. if (len > 0 && iranges[1] != 0) {
  341. printk(KERN_INFO "OpenPIC irqs %d..%d in IDU\n",
  342. iranges[0], iranges[0] + iranges[1] - 1);
  343. idu_size = iranges[1];
  344. }
  345. if (len > 1)
  346. isu_size = iranges[3];
  347. chrp_mpic = mpic_alloc(opaddr, MPIC_PRIMARY,
  348. isu_size, NUM_ISA_INTERRUPTS, irq_count,
  349. NR_IRQS - 4, init_senses, irq_count,
  350. " MPIC ");
  351. if (chrp_mpic == NULL) {
  352. printk(KERN_ERR "Failed to allocate MPIC structure\n");
  353. return;
  354. }
  355. j = na - 1;
  356. for (i = 1; i < len; ++i) {
  357. iranges += 2;
  358. j += na;
  359. printk(KERN_INFO "OpenPIC irqs %d..%d in ISU at %x\n",
  360. iranges[0], iranges[0] + iranges[1] - 1,
  361. opprop[j]);
  362. mpic_assign_isu(chrp_mpic, i - 1, opprop[j]);
  363. }
  364. mpic_init(chrp_mpic);
  365. mpic_setup_cascade(NUM_ISA_INTERRUPTS, i8259_irq_cascade, NULL);
  366. }
  367. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  368. static struct irqaction xmon_irqaction = {
  369. .handler = xmon_irq,
  370. .mask = CPU_MASK_NONE,
  371. .name = "XMON break",
  372. };
  373. #endif
  374. void __init chrp_init_IRQ(void)
  375. {
  376. struct device_node *np;
  377. unsigned long chrp_int_ack = 0;
  378. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  379. struct device_node *kbd;
  380. #endif
  381. for (np = find_devices("pci"); np != NULL; np = np->next) {
  382. unsigned int *addrp = (unsigned int *)
  383. get_property(np, "8259-interrupt-acknowledge", NULL);
  384. if (addrp == NULL)
  385. continue;
  386. chrp_int_ack = addrp[prom_n_addr_cells(np)-1];
  387. break;
  388. }
  389. if (np == NULL)
  390. printk(KERN_ERR "Cannot find PCI interrupt acknowledge address\n");
  391. chrp_find_openpic();
  392. i8259_init(chrp_int_ack, 0);
  393. if (_chrp_type == _CHRP_Pegasos)
  394. ppc_md.get_irq = i8259_irq;
  395. else
  396. ppc_md.get_irq = mpic_get_irq;
  397. #if defined(CONFIG_VT) && defined(CONFIG_INPUT_ADBHID) && defined(XMON)
  398. /* see if there is a keyboard in the device tree
  399. with a parent of type "adb" */
  400. for (kbd = find_devices("keyboard"); kbd; kbd = kbd->next)
  401. if (kbd->parent && kbd->parent->type
  402. && strcmp(kbd->parent->type, "adb") == 0)
  403. break;
  404. if (kbd)
  405. setup_irq(HYDRA_INT_ADB_NMI, &xmon_irqaction);
  406. #endif
  407. }
  408. void __init
  409. chrp_init2(void)
  410. {
  411. #ifdef CONFIG_NVRAM
  412. chrp_nvram_init();
  413. #endif
  414. request_region(0x20,0x20,"pic1");
  415. request_region(0xa0,0x20,"pic2");
  416. request_region(0x00,0x20,"dma1");
  417. request_region(0x40,0x20,"timer");
  418. request_region(0x80,0x10,"dma page reg");
  419. request_region(0xc0,0x20,"dma2");
  420. if (ppc_md.progress)
  421. ppc_md.progress(" Have fun! ", 0x7777);
  422. }
  423. void __init chrp_init(void)
  424. {
  425. ISA_DMA_THRESHOLD = ~0L;
  426. DMA_MODE_READ = 0x44;
  427. DMA_MODE_WRITE = 0x48;
  428. isa_io_base = CHRP_ISA_IO_BASE; /* default value */
  429. ppc_do_canonicalize_irqs = 1;
  430. /* Assume we have an 8259... */
  431. __irq_offset_value = NUM_ISA_INTERRUPTS;
  432. ppc_md.setup_arch = chrp_setup_arch;
  433. ppc_md.show_cpuinfo = chrp_show_cpuinfo;
  434. ppc_md.init_IRQ = chrp_init_IRQ;
  435. ppc_md.init = chrp_init2;
  436. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  437. ppc_md.restart = rtas_restart;
  438. ppc_md.power_off = rtas_power_off;
  439. ppc_md.halt = rtas_halt;
  440. ppc_md.time_init = chrp_time_init;
  441. ppc_md.calibrate_decr = chrp_calibrate_decr;
  442. /* this may get overridden with rtas routines later... */
  443. ppc_md.set_rtc_time = chrp_set_rtc_time;
  444. ppc_md.get_rtc_time = chrp_get_rtc_time;
  445. #ifdef CONFIG_SMP
  446. smp_ops = &chrp_smp_ops;
  447. #endif /* CONFIG_SMP */
  448. }