ip27-init.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General
  3. * Public License. See the file "COPYING" in the main directory of this
  4. * archive for more details.
  5. *
  6. * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
  7. * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/sched.h>
  12. #include <linux/mm.h>
  13. #include <linux/module.h>
  14. #include <linux/cpumask.h>
  15. #include <asm/cpu.h>
  16. #include <asm/io.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/time.h>
  19. #include <asm/sn/types.h>
  20. #include <asm/sn/sn0/addrs.h>
  21. #include <asm/sn/sn0/hubni.h>
  22. #include <asm/sn/sn0/hubio.h>
  23. #include <asm/sn/klconfig.h>
  24. #include <asm/sn/ioc3.h>
  25. #include <asm/mipsregs.h>
  26. #include <asm/sn/gda.h>
  27. #include <asm/sn/hub.h>
  28. #include <asm/sn/intr.h>
  29. #include <asm/current.h>
  30. #include <asm/processor.h>
  31. #include <asm/mmu_context.h>
  32. #include <asm/thread_info.h>
  33. #include <asm/sn/launch.h>
  34. #include <asm/sn/sn_private.h>
  35. #include <asm/sn/sn0/ip27.h>
  36. #include <asm/sn/mapped_kernel.h>
  37. #define CPU_NONE (cpuid_t)-1
  38. static DECLARE_BITMAP(hub_init_mask, MAX_COMPACT_NODES);
  39. nasid_t master_nasid = INVALID_NASID;
  40. cnodeid_t nasid_to_compact_node[MAX_NASIDS];
  41. nasid_t compact_to_nasid_node[MAX_COMPACT_NODES];
  42. cnodeid_t cpuid_to_compact_node[MAXCPUS];
  43. EXPORT_SYMBOL(nasid_to_compact_node);
  44. struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
  45. EXPORT_SYMBOL_GPL(sn_cpu_info);
  46. extern void pcibr_setup(cnodeid_t);
  47. extern void xtalk_probe_node(cnodeid_t nid);
  48. static void __cpuinit per_hub_init(cnodeid_t cnode)
  49. {
  50. struct hub_data *hub = hub_data(cnode);
  51. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  52. int i;
  53. cpu_set(smp_processor_id(), hub->h_cpus);
  54. if (test_and_set_bit(cnode, hub_init_mask))
  55. return;
  56. /*
  57. * Set CRB timeout at 5ms, (< PI timeout of 10ms)
  58. */
  59. REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
  60. REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
  61. hub_rtc_init(cnode);
  62. xtalk_probe_node(cnode);
  63. #ifdef CONFIG_REPLICATE_EXHANDLERS
  64. /*
  65. * If this is not a headless node initialization,
  66. * copy over the caliased exception handlers.
  67. */
  68. if (get_compact_nodeid() == cnode) {
  69. extern char except_vec2_generic, except_vec3_generic;
  70. extern void build_tlb_refill_handler(void);
  71. memcpy((void *)(CKSEG0 + 0x100), &except_vec2_generic, 0x80);
  72. memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x80);
  73. build_tlb_refill_handler();
  74. memcpy((void *)(CKSEG0 + 0x100), (void *) CKSEG0, 0x80);
  75. memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x100);
  76. __flush_cache_all();
  77. }
  78. #endif
  79. /*
  80. * Some interrupts are reserved by hardware or by software convention.
  81. * Mark these as reserved right away so they won't be used accidently
  82. * later.
  83. */
  84. for (i = 0; i <= BASE_PCI_IRQ; i++) {
  85. __set_bit(i, hub->irq_alloc_mask);
  86. LOCAL_HUB_CLR_INTR(INT_PEND0_BASELVL + i);
  87. }
  88. __set_bit(IP_PEND0_6_63, hub->irq_alloc_mask);
  89. LOCAL_HUB_S(PI_INT_PEND_MOD, IP_PEND0_6_63);
  90. for (i = NI_BRDCAST_ERR_A; i <= MSC_PANIC_INTR; i++) {
  91. __set_bit(i, hub->irq_alloc_mask);
  92. LOCAL_HUB_CLR_INTR(INT_PEND1_BASELVL + i);
  93. }
  94. }
  95. void __cpuinit per_cpu_init(void)
  96. {
  97. int cpu = smp_processor_id();
  98. int slice = LOCAL_HUB_L(PI_CPU_NUM);
  99. cnodeid_t cnode = get_compact_nodeid();
  100. struct hub_data *hub = hub_data(cnode);
  101. struct slice_data *si = hub->slice + slice;
  102. int i;
  103. if (test_and_set_bit(slice, &hub->slice_map))
  104. return;
  105. clear_c0_status(ST0_IM);
  106. per_hub_init(cnode);
  107. for (i = 0; i < LEVELS_PER_SLICE; i++)
  108. si->level_to_irq[i] = -1;
  109. /*
  110. * We use this so we can find the local hub's data as fast as only
  111. * possible.
  112. */
  113. cpu_data[cpu].data = si;
  114. cpu_time_init();
  115. install_ipi();
  116. /* Install our NMI handler if symmon hasn't installed one. */
  117. install_cpu_nmi_handler(cputoslice(cpu));
  118. set_c0_status(SRB_DEV0 | SRB_DEV1);
  119. }
  120. /*
  121. * get_nasid() returns the physical node id number of the caller.
  122. */
  123. nasid_t
  124. get_nasid(void)
  125. {
  126. return (nasid_t)((LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_NODEID_MASK)
  127. >> NSRI_NODEID_SHFT);
  128. }
  129. /*
  130. * Map the physical node id to a virtual node id (virtual node ids are contiguous).
  131. */
  132. cnodeid_t get_compact_nodeid(void)
  133. {
  134. return NASID_TO_COMPACT_NODEID(get_nasid());
  135. }
  136. static inline void ioc3_eth_init(void)
  137. {
  138. struct ioc3 *ioc3;
  139. nasid_t nid;
  140. nid = get_nasid();
  141. ioc3 = (struct ioc3 *) KL_CONFIG_CH_CONS_INFO(nid)->memory_base;
  142. ioc3->eier = 0;
  143. }
  144. extern void ip27_reboot_setup(void);
  145. void __init plat_mem_setup(void)
  146. {
  147. hubreg_t p, e, n_mode;
  148. nasid_t nid;
  149. ip27_reboot_setup();
  150. /*
  151. * hub_rtc init and cpu clock intr enabled for later calibrate_delay.
  152. */
  153. nid = get_nasid();
  154. printk("IP27: Running on node %d.\n", nid);
  155. p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1;
  156. e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1;
  157. printk("Node %d has %s primary CPU%s.\n", nid,
  158. p ? "a" : "no",
  159. e ? ", CPU is running" : "");
  160. p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1;
  161. e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1;
  162. printk("Node %d has %s secondary CPU%s.\n", nid,
  163. p ? "a" : "no",
  164. e ? ", CPU is running" : "");
  165. /*
  166. * Try to catch kernel missconfigurations and give user an
  167. * indication what option to select.
  168. */
  169. n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK;
  170. printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M');
  171. #ifdef CONFIG_SGI_SN_N_MODE
  172. if (!n_mode)
  173. panic("Kernel compiled for M mode.");
  174. #else
  175. if (n_mode)
  176. panic("Kernel compiled for N mode.");
  177. #endif
  178. ioc3_eth_init();
  179. per_cpu_init();
  180. set_io_port_base(IO_BASE);
  181. }