setup.c 12 KB

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