voyager_smp.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /* Copyright (C) 1999,2001
  3. *
  4. * Author: J.E.J.Bottomley@HansenPartnership.com
  5. *
  6. * linux/arch/i386/kernel/voyager_smp.c
  7. *
  8. * This file provides all the same external entries as smp.c but uses
  9. * the voyager hal to provide the functionality
  10. */
  11. #include <linux/module.h>
  12. #include <linux/mm.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/delay.h>
  15. #include <linux/mc146818rtc.h>
  16. #include <linux/cache.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/bootmem.h>
  21. #include <linux/completion.h>
  22. #include <asm/desc.h>
  23. #include <asm/voyager.h>
  24. #include <asm/vic.h>
  25. #include <asm/mtrr.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/tlbflush.h>
  28. #include <asm/arch_hooks.h>
  29. /* TLB state -- visible externally, indexed physically */
  30. DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate) = { &init_mm, 0 };
  31. /* CPU IRQ affinity -- set to all ones initially */
  32. static unsigned long cpu_irq_affinity[NR_CPUS] __cacheline_aligned =
  33. {[0 ... NR_CPUS-1] = ~0UL };
  34. /* per CPU data structure (for /proc/cpuinfo et al), visible externally
  35. * indexed physically */
  36. DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);
  37. EXPORT_PER_CPU_SYMBOL(cpu_info);
  38. /* physical ID of the CPU used to boot the system */
  39. unsigned char boot_cpu_id;
  40. /* The memory line addresses for the Quad CPIs */
  41. struct voyager_qic_cpi *voyager_quad_cpi_addr[NR_CPUS] __cacheline_aligned;
  42. /* The masks for the Extended VIC processors, filled in by cat_init */
  43. __u32 voyager_extended_vic_processors = 0;
  44. /* Masks for the extended Quad processors which cannot be VIC booted */
  45. __u32 voyager_allowed_boot_processors = 0;
  46. /* The mask for the Quad Processors (both extended and non-extended) */
  47. __u32 voyager_quad_processors = 0;
  48. /* Total count of live CPUs, used in process.c to display
  49. * the CPU information and in irq.c for the per CPU irq
  50. * activity count. Finally exported by i386_ksyms.c */
  51. static int voyager_extended_cpus = 1;
  52. /* Have we found an SMP box - used by time.c to do the profiling
  53. interrupt for timeslicing; do not set to 1 until the per CPU timer
  54. interrupt is active */
  55. int smp_found_config = 0;
  56. /* Used for the invalidate map that's also checked in the spinlock */
  57. static volatile unsigned long smp_invalidate_needed;
  58. /* Bitmask of currently online CPUs - used by setup.c for
  59. /proc/cpuinfo, visible externally but still physical */
  60. cpumask_t cpu_online_map = CPU_MASK_NONE;
  61. EXPORT_SYMBOL(cpu_online_map);
  62. /* Bitmask of CPUs present in the system - exported by i386_syms.c, used
  63. * by scheduler but indexed physically */
  64. cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
  65. /* The internal functions */
  66. static void send_CPI(__u32 cpuset, __u8 cpi);
  67. static void ack_CPI(__u8 cpi);
  68. static int ack_QIC_CPI(__u8 cpi);
  69. static void ack_special_QIC_CPI(__u8 cpi);
  70. static void ack_VIC_CPI(__u8 cpi);
  71. static void send_CPI_allbutself(__u8 cpi);
  72. static void mask_vic_irq(unsigned int irq);
  73. static void unmask_vic_irq(unsigned int irq);
  74. static unsigned int startup_vic_irq(unsigned int irq);
  75. static void enable_local_vic_irq(unsigned int irq);
  76. static void disable_local_vic_irq(unsigned int irq);
  77. static void before_handle_vic_irq(unsigned int irq);
  78. static void after_handle_vic_irq(unsigned int irq);
  79. static void set_vic_irq_affinity(unsigned int irq, cpumask_t mask);
  80. static void ack_vic_irq(unsigned int irq);
  81. static void vic_enable_cpi(void);
  82. static void do_boot_cpu(__u8 cpuid);
  83. static void do_quad_bootstrap(void);
  84. int hard_smp_processor_id(void);
  85. int safe_smp_processor_id(void);
  86. /* Inline functions */
  87. static inline void send_one_QIC_CPI(__u8 cpu, __u8 cpi)
  88. {
  89. voyager_quad_cpi_addr[cpu]->qic_cpi[cpi].cpi =
  90. (smp_processor_id() << 16) + cpi;
  91. }
  92. static inline void send_QIC_CPI(__u32 cpuset, __u8 cpi)
  93. {
  94. int cpu;
  95. for_each_online_cpu(cpu) {
  96. if (cpuset & (1 << cpu)) {
  97. #ifdef VOYAGER_DEBUG
  98. if (!cpu_isset(cpu, cpu_online_map))
  99. VDEBUG(("CPU%d sending cpi %d to CPU%d not in "
  100. "cpu_online_map\n",
  101. hard_smp_processor_id(), cpi, cpu));
  102. #endif
  103. send_one_QIC_CPI(cpu, cpi - QIC_CPI_OFFSET);
  104. }
  105. }
  106. }
  107. static inline void wrapper_smp_local_timer_interrupt(void)
  108. {
  109. irq_enter();
  110. smp_local_timer_interrupt();
  111. irq_exit();
  112. }
  113. static inline void send_one_CPI(__u8 cpu, __u8 cpi)
  114. {
  115. if (voyager_quad_processors & (1 << cpu))
  116. send_one_QIC_CPI(cpu, cpi - QIC_CPI_OFFSET);
  117. else
  118. send_CPI(1 << cpu, cpi);
  119. }
  120. static inline void send_CPI_allbutself(__u8 cpi)
  121. {
  122. __u8 cpu = smp_processor_id();
  123. __u32 mask = cpus_addr(cpu_online_map)[0] & ~(1 << cpu);
  124. send_CPI(mask, cpi);
  125. }
  126. static inline int is_cpu_quad(void)
  127. {
  128. __u8 cpumask = inb(VIC_PROC_WHO_AM_I);
  129. return ((cpumask & QUAD_IDENTIFIER) == QUAD_IDENTIFIER);
  130. }
  131. static inline int is_cpu_extended(void)
  132. {
  133. __u8 cpu = hard_smp_processor_id();
  134. return (voyager_extended_vic_processors & (1 << cpu));
  135. }
  136. static inline int is_cpu_vic_boot(void)
  137. {
  138. __u8 cpu = hard_smp_processor_id();
  139. return (voyager_extended_vic_processors
  140. & voyager_allowed_boot_processors & (1 << cpu));
  141. }
  142. static inline void ack_CPI(__u8 cpi)
  143. {
  144. switch (cpi) {
  145. case VIC_CPU_BOOT_CPI:
  146. if (is_cpu_quad() && !is_cpu_vic_boot())
  147. ack_QIC_CPI(cpi);
  148. else
  149. ack_VIC_CPI(cpi);
  150. break;
  151. case VIC_SYS_INT:
  152. case VIC_CMN_INT:
  153. /* These are slightly strange. Even on the Quad card,
  154. * They are vectored as VIC CPIs */
  155. if (is_cpu_quad())
  156. ack_special_QIC_CPI(cpi);
  157. else
  158. ack_VIC_CPI(cpi);
  159. break;
  160. default:
  161. printk("VOYAGER ERROR: CPI%d is in common CPI code\n", cpi);
  162. break;
  163. }
  164. }
  165. /* local variables */
  166. /* The VIC IRQ descriptors -- these look almost identical to the
  167. * 8259 IRQs except that masks and things must be kept per processor
  168. */
  169. static struct irq_chip vic_chip = {
  170. .name = "VIC",
  171. .startup = startup_vic_irq,
  172. .mask = mask_vic_irq,
  173. .unmask = unmask_vic_irq,
  174. .set_affinity = set_vic_irq_affinity,
  175. };
  176. /* used to count up as CPUs are brought on line (starts at 0) */
  177. static int cpucount = 0;
  178. /* steal a page from the bottom of memory for the trampoline and
  179. * squirrel its address away here. This will be in kernel virtual
  180. * space */
  181. static __u32 trampoline_base;
  182. /* The per cpu profile stuff - used in smp_local_timer_interrupt */
  183. static DEFINE_PER_CPU(int, prof_multiplier) = 1;
  184. static DEFINE_PER_CPU(int, prof_old_multiplier) = 1;
  185. static DEFINE_PER_CPU(int, prof_counter) = 1;
  186. /* the map used to check if a CPU has booted */
  187. static __u32 cpu_booted_map;
  188. /* the synchronize flag used to hold all secondary CPUs spinning in
  189. * a tight loop until the boot sequence is ready for them */
  190. static cpumask_t smp_commenced_mask = CPU_MASK_NONE;
  191. /* This is for the new dynamic CPU boot code */
  192. cpumask_t cpu_callin_map = CPU_MASK_NONE;
  193. cpumask_t cpu_callout_map = CPU_MASK_NONE;
  194. cpumask_t cpu_possible_map = CPU_MASK_NONE;
  195. EXPORT_SYMBOL(cpu_possible_map);
  196. /* The per processor IRQ masks (these are usually kept in sync) */
  197. static __u16 vic_irq_mask[NR_CPUS] __cacheline_aligned;
  198. /* the list of IRQs to be enabled by the VIC_ENABLE_IRQ_CPI */
  199. static __u16 vic_irq_enable_mask[NR_CPUS] __cacheline_aligned = { 0 };
  200. /* Lock for enable/disable of VIC interrupts */
  201. static __cacheline_aligned DEFINE_SPINLOCK(vic_irq_lock);
  202. /* The boot processor is correctly set up in PC mode when it
  203. * comes up, but the secondaries need their master/slave 8259
  204. * pairs initializing correctly */
  205. /* Interrupt counters (per cpu) and total - used to try to
  206. * even up the interrupt handling routines */
  207. static long vic_intr_total = 0;
  208. static long vic_intr_count[NR_CPUS] __cacheline_aligned = { 0 };
  209. static unsigned long vic_tick[NR_CPUS] __cacheline_aligned = { 0 };
  210. /* Since we can only use CPI0, we fake all the other CPIs */
  211. static unsigned long vic_cpi_mailbox[NR_CPUS] __cacheline_aligned;
  212. /* debugging routine to read the isr of the cpu's pic */
  213. static inline __u16 vic_read_isr(void)
  214. {
  215. __u16 isr;
  216. outb(0x0b, 0xa0);
  217. isr = inb(0xa0) << 8;
  218. outb(0x0b, 0x20);
  219. isr |= inb(0x20);
  220. return isr;
  221. }
  222. static __init void qic_setup(void)
  223. {
  224. if (!is_cpu_quad()) {
  225. /* not a quad, no setup */
  226. return;
  227. }
  228. outb(QIC_DEFAULT_MASK0, QIC_MASK_REGISTER0);
  229. outb(QIC_CPI_ENABLE, QIC_MASK_REGISTER1);
  230. if (is_cpu_extended()) {
  231. /* the QIC duplicate of the VIC base register */
  232. outb(VIC_DEFAULT_CPI_BASE, QIC_VIC_CPI_BASE_REGISTER);
  233. outb(QIC_DEFAULT_CPI_BASE, QIC_CPI_BASE_REGISTER);
  234. /* FIXME: should set up the QIC timer and memory parity
  235. * error vectors here */
  236. }
  237. }
  238. static __init void vic_setup_pic(void)
  239. {
  240. outb(1, VIC_REDIRECT_REGISTER_1);
  241. /* clear the claim registers for dynamic routing */
  242. outb(0, VIC_CLAIM_REGISTER_0);
  243. outb(0, VIC_CLAIM_REGISTER_1);
  244. outb(0, VIC_PRIORITY_REGISTER);
  245. /* Set the Primary and Secondary Microchannel vector
  246. * bases to be the same as the ordinary interrupts
  247. *
  248. * FIXME: This would be more efficient using separate
  249. * vectors. */
  250. outb(FIRST_EXTERNAL_VECTOR, VIC_PRIMARY_MC_BASE);
  251. outb(FIRST_EXTERNAL_VECTOR, VIC_SECONDARY_MC_BASE);
  252. /* Now initiallise the master PIC belonging to this CPU by
  253. * sending the four ICWs */
  254. /* ICW1: level triggered, ICW4 needed */
  255. outb(0x19, 0x20);
  256. /* ICW2: vector base */
  257. outb(FIRST_EXTERNAL_VECTOR, 0x21);
  258. /* ICW3: slave at line 2 */
  259. outb(0x04, 0x21);
  260. /* ICW4: 8086 mode */
  261. outb(0x01, 0x21);
  262. /* now the same for the slave PIC */
  263. /* ICW1: level trigger, ICW4 needed */
  264. outb(0x19, 0xA0);
  265. /* ICW2: slave vector base */
  266. outb(FIRST_EXTERNAL_VECTOR + 8, 0xA1);
  267. /* ICW3: slave ID */
  268. outb(0x02, 0xA1);
  269. /* ICW4: 8086 mode */
  270. outb(0x01, 0xA1);
  271. }
  272. static void do_quad_bootstrap(void)
  273. {
  274. if (is_cpu_quad() && is_cpu_vic_boot()) {
  275. int i;
  276. unsigned long flags;
  277. __u8 cpuid = hard_smp_processor_id();
  278. local_irq_save(flags);
  279. for (i = 0; i < 4; i++) {
  280. /* FIXME: this would be >>3 &0x7 on the 32 way */
  281. if (((cpuid >> 2) & 0x03) == i)
  282. /* don't lower our own mask! */
  283. continue;
  284. /* masquerade as local Quad CPU */
  285. outb(QIC_CPUID_ENABLE | i, QIC_PROCESSOR_ID);
  286. /* enable the startup CPI */
  287. outb(QIC_BOOT_CPI_MASK, QIC_MASK_REGISTER1);
  288. /* restore cpu id */
  289. outb(0, QIC_PROCESSOR_ID);
  290. }
  291. local_irq_restore(flags);
  292. }
  293. }
  294. /* Set up all the basic stuff: read the SMP config and make all the
  295. * SMP information reflect only the boot cpu. All others will be
  296. * brought on-line later. */
  297. void __init find_smp_config(void)
  298. {
  299. int i;
  300. boot_cpu_id = hard_smp_processor_id();
  301. printk("VOYAGER SMP: Boot cpu is %d\n", boot_cpu_id);
  302. /* initialize the CPU structures (moved from smp_boot_cpus) */
  303. for (i = 0; i < NR_CPUS; i++) {
  304. cpu_irq_affinity[i] = ~0;
  305. }
  306. cpu_online_map = cpumask_of_cpu(boot_cpu_id);
  307. /* The boot CPU must be extended */
  308. voyager_extended_vic_processors = 1 << boot_cpu_id;
  309. /* initially, all of the first 8 CPUs can boot */
  310. voyager_allowed_boot_processors = 0xff;
  311. /* set up everything for just this CPU, we can alter
  312. * this as we start the other CPUs later */
  313. /* now get the CPU disposition from the extended CMOS */
  314. cpus_addr(phys_cpu_present_map)[0] =
  315. voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK);
  316. cpus_addr(phys_cpu_present_map)[0] |=
  317. voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 1) << 8;
  318. cpus_addr(phys_cpu_present_map)[0] |=
  319. voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK +
  320. 2) << 16;
  321. cpus_addr(phys_cpu_present_map)[0] |=
  322. voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK +
  323. 3) << 24;
  324. cpu_possible_map = phys_cpu_present_map;
  325. printk("VOYAGER SMP: phys_cpu_present_map = 0x%lx\n",
  326. cpus_addr(phys_cpu_present_map)[0]);
  327. /* Here we set up the VIC to enable SMP */
  328. /* enable the CPIs by writing the base vector to their register */
  329. outb(VIC_DEFAULT_CPI_BASE, VIC_CPI_BASE_REGISTER);
  330. outb(1, VIC_REDIRECT_REGISTER_1);
  331. /* set the claim registers for static routing --- Boot CPU gets
  332. * all interrupts untill all other CPUs started */
  333. outb(0xff, VIC_CLAIM_REGISTER_0);
  334. outb(0xff, VIC_CLAIM_REGISTER_1);
  335. /* Set the Primary and Secondary Microchannel vector
  336. * bases to be the same as the ordinary interrupts
  337. *
  338. * FIXME: This would be more efficient using separate
  339. * vectors. */
  340. outb(FIRST_EXTERNAL_VECTOR, VIC_PRIMARY_MC_BASE);
  341. outb(FIRST_EXTERNAL_VECTOR, VIC_SECONDARY_MC_BASE);
  342. /* Finally tell the firmware that we're driving */
  343. outb(inb(VOYAGER_SUS_IN_CONTROL_PORT) | VOYAGER_IN_CONTROL_FLAG,
  344. VOYAGER_SUS_IN_CONTROL_PORT);
  345. current_thread_info()->cpu = boot_cpu_id;
  346. x86_write_percpu(cpu_number, boot_cpu_id);
  347. }
  348. /*
  349. * The bootstrap kernel entry code has set these up. Save them
  350. * for a given CPU, id is physical */
  351. void __init smp_store_cpu_info(int id)
  352. {
  353. struct cpuinfo_x86 *c = &cpu_data(id);
  354. *c = boot_cpu_data;
  355. identify_secondary_cpu(c);
  356. }
  357. /* set up the trampoline and return the physical address of the code */
  358. static __u32 __init setup_trampoline(void)
  359. {
  360. /* these two are global symbols in trampoline.S */
  361. extern const __u8 trampoline_end[];
  362. extern const __u8 trampoline_data[];
  363. memcpy((__u8 *) trampoline_base, trampoline_data,
  364. trampoline_end - trampoline_data);
  365. return virt_to_phys((__u8 *) trampoline_base);
  366. }
  367. /* Routine initially called when a non-boot CPU is brought online */
  368. static void __init start_secondary(void *unused)
  369. {
  370. __u8 cpuid = hard_smp_processor_id();
  371. /* external functions not defined in the headers */
  372. extern void calibrate_delay(void);
  373. cpu_init();
  374. /* OK, we're in the routine */
  375. ack_CPI(VIC_CPU_BOOT_CPI);
  376. /* setup the 8259 master slave pair belonging to this CPU ---
  377. * we won't actually receive any until the boot CPU
  378. * relinquishes it's static routing mask */
  379. vic_setup_pic();
  380. qic_setup();
  381. if (is_cpu_quad() && !is_cpu_vic_boot()) {
  382. /* clear the boot CPI */
  383. __u8 dummy;
  384. dummy =
  385. voyager_quad_cpi_addr[cpuid]->qic_cpi[VIC_CPU_BOOT_CPI].cpi;
  386. printk("read dummy %d\n", dummy);
  387. }
  388. /* lower the mask to receive CPIs */
  389. vic_enable_cpi();
  390. VDEBUG(("VOYAGER SMP: CPU%d, stack at about %p\n", cpuid, &cpuid));
  391. /* enable interrupts */
  392. local_irq_enable();
  393. /* get our bogomips */
  394. calibrate_delay();
  395. /* save our processor parameters */
  396. smp_store_cpu_info(cpuid);
  397. /* if we're a quad, we may need to bootstrap other CPUs */
  398. do_quad_bootstrap();
  399. /* FIXME: this is rather a poor hack to prevent the CPU
  400. * activating softirqs while it's supposed to be waiting for
  401. * permission to proceed. Without this, the new per CPU stuff
  402. * in the softirqs will fail */
  403. local_irq_disable();
  404. cpu_set(cpuid, cpu_callin_map);
  405. /* signal that we're done */
  406. cpu_booted_map = 1;
  407. while (!cpu_isset(cpuid, smp_commenced_mask))
  408. rep_nop();
  409. local_irq_enable();
  410. local_flush_tlb();
  411. cpu_set(cpuid, cpu_online_map);
  412. wmb();
  413. cpu_idle();
  414. }
  415. /* Routine to kick start the given CPU and wait for it to report ready
  416. * (or timeout in startup). When this routine returns, the requested
  417. * CPU is either fully running and configured or known to be dead.
  418. *
  419. * We call this routine sequentially 1 CPU at a time, so no need for
  420. * locking */
  421. static void __init do_boot_cpu(__u8 cpu)
  422. {
  423. struct task_struct *idle;
  424. int timeout;
  425. unsigned long flags;
  426. int quad_boot = (1 << cpu) & voyager_quad_processors
  427. & ~(voyager_extended_vic_processors
  428. & voyager_allowed_boot_processors);
  429. /* This is an area in head.S which was used to set up the
  430. * initial kernel stack. We need to alter this to give the
  431. * booting CPU a new stack (taken from its idle process) */
  432. extern struct {
  433. __u8 *esp;
  434. unsigned short ss;
  435. } stack_start;
  436. /* This is the format of the CPI IDT gate (in real mode) which
  437. * we're hijacking to boot the CPU */
  438. union IDTFormat {
  439. struct seg {
  440. __u16 Offset;
  441. __u16 Segment;
  442. } idt;
  443. __u32 val;
  444. } hijack_source;
  445. __u32 *hijack_vector;
  446. __u32 start_phys_address = setup_trampoline();
  447. /* There's a clever trick to this: The linux trampoline is
  448. * compiled to begin at absolute location zero, so make the
  449. * address zero but have the data segment selector compensate
  450. * for the actual address */
  451. hijack_source.idt.Offset = start_phys_address & 0x000F;
  452. hijack_source.idt.Segment = (start_phys_address >> 4) & 0xFFFF;
  453. cpucount++;
  454. alternatives_smp_switch(1);
  455. idle = fork_idle(cpu);
  456. if (IS_ERR(idle))
  457. panic("failed fork for CPU%d", cpu);
  458. idle->thread.eip = (unsigned long)start_secondary;
  459. /* init_tasks (in sched.c) is indexed logically */
  460. stack_start.esp = (void *)idle->thread.esp;
  461. init_gdt(cpu);
  462. per_cpu(current_task, cpu) = idle;
  463. early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
  464. irq_ctx_init(cpu);
  465. /* Note: Don't modify initial ss override */
  466. VDEBUG(("VOYAGER SMP: Booting CPU%d at 0x%lx[%x:%x], stack %p\n", cpu,
  467. (unsigned long)hijack_source.val, hijack_source.idt.Segment,
  468. hijack_source.idt.Offset, stack_start.esp));
  469. /* init lowmem identity mapping */
  470. clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
  471. min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS));
  472. flush_tlb_all();
  473. if (quad_boot) {
  474. printk("CPU %d: non extended Quad boot\n", cpu);
  475. hijack_vector =
  476. (__u32 *)
  477. phys_to_virt((VIC_CPU_BOOT_CPI + QIC_DEFAULT_CPI_BASE) * 4);
  478. *hijack_vector = hijack_source.val;
  479. } else {
  480. printk("CPU%d: extended VIC boot\n", cpu);
  481. hijack_vector =
  482. (__u32 *)
  483. phys_to_virt((VIC_CPU_BOOT_CPI + VIC_DEFAULT_CPI_BASE) * 4);
  484. *hijack_vector = hijack_source.val;
  485. /* VIC errata, may also receive interrupt at this address */
  486. hijack_vector =
  487. (__u32 *)
  488. phys_to_virt((VIC_CPU_BOOT_ERRATA_CPI +
  489. VIC_DEFAULT_CPI_BASE) * 4);
  490. *hijack_vector = hijack_source.val;
  491. }
  492. /* All non-boot CPUs start with interrupts fully masked. Need
  493. * to lower the mask of the CPI we're about to send. We do
  494. * this in the VIC by masquerading as the processor we're
  495. * about to boot and lowering its interrupt mask */
  496. local_irq_save(flags);
  497. if (quad_boot) {
  498. send_one_QIC_CPI(cpu, VIC_CPU_BOOT_CPI);
  499. } else {
  500. outb(VIC_CPU_MASQUERADE_ENABLE | cpu, VIC_PROCESSOR_ID);
  501. /* here we're altering registers belonging to `cpu' */
  502. outb(VIC_BOOT_INTERRUPT_MASK, 0x21);
  503. /* now go back to our original identity */
  504. outb(boot_cpu_id, VIC_PROCESSOR_ID);
  505. /* and boot the CPU */
  506. send_CPI((1 << cpu), VIC_CPU_BOOT_CPI);
  507. }
  508. cpu_booted_map = 0;
  509. local_irq_restore(flags);
  510. /* now wait for it to become ready (or timeout) */
  511. for (timeout = 0; timeout < 50000; timeout++) {
  512. if (cpu_booted_map)
  513. break;
  514. udelay(100);
  515. }
  516. /* reset the page table */
  517. zap_low_mappings();
  518. if (cpu_booted_map) {
  519. VDEBUG(("CPU%d: Booted successfully, back in CPU %d\n",
  520. cpu, smp_processor_id()));
  521. printk("CPU%d: ", cpu);
  522. print_cpu_info(&cpu_data(cpu));
  523. wmb();
  524. cpu_set(cpu, cpu_callout_map);
  525. cpu_set(cpu, cpu_present_map);
  526. } else {
  527. printk("CPU%d FAILED TO BOOT: ", cpu);
  528. if (*
  529. ((volatile unsigned char *)phys_to_virt(start_phys_address))
  530. == 0xA5)
  531. printk("Stuck.\n");
  532. else
  533. printk("Not responding.\n");
  534. cpucount--;
  535. }
  536. }
  537. void __init smp_boot_cpus(void)
  538. {
  539. int i;
  540. /* CAT BUS initialisation must be done after the memory */
  541. /* FIXME: The L4 has a catbus too, it just needs to be
  542. * accessed in a totally different way */
  543. if (voyager_level == 5) {
  544. voyager_cat_init();
  545. /* now that the cat has probed the Voyager System Bus, sanity
  546. * check the cpu map */
  547. if (((voyager_quad_processors | voyager_extended_vic_processors)
  548. & cpus_addr(phys_cpu_present_map)[0]) !=
  549. cpus_addr(phys_cpu_present_map)[0]) {
  550. /* should panic */
  551. printk("\n\n***WARNING*** "
  552. "Sanity check of CPU present map FAILED\n");
  553. }
  554. } else if (voyager_level == 4)
  555. voyager_extended_vic_processors =
  556. cpus_addr(phys_cpu_present_map)[0];
  557. /* this sets up the idle task to run on the current cpu */
  558. voyager_extended_cpus = 1;
  559. /* Remove the global_irq_holder setting, it triggers a BUG() on
  560. * schedule at the moment */
  561. //global_irq_holder = boot_cpu_id;
  562. /* FIXME: Need to do something about this but currently only works
  563. * on CPUs with a tsc which none of mine have.
  564. smp_tune_scheduling();
  565. */
  566. smp_store_cpu_info(boot_cpu_id);
  567. printk("CPU%d: ", boot_cpu_id);
  568. print_cpu_info(&cpu_data(boot_cpu_id));
  569. if (is_cpu_quad()) {
  570. /* booting on a Quad CPU */
  571. printk("VOYAGER SMP: Boot CPU is Quad\n");
  572. qic_setup();
  573. do_quad_bootstrap();
  574. }
  575. /* enable our own CPIs */
  576. vic_enable_cpi();
  577. cpu_set(boot_cpu_id, cpu_online_map);
  578. cpu_set(boot_cpu_id, cpu_callout_map);
  579. /* loop over all the extended VIC CPUs and boot them. The
  580. * Quad CPUs must be bootstrapped by their extended VIC cpu */
  581. for (i = 0; i < NR_CPUS; i++) {
  582. if (i == boot_cpu_id || !cpu_isset(i, phys_cpu_present_map))
  583. continue;
  584. do_boot_cpu(i);
  585. /* This udelay seems to be needed for the Quad boots
  586. * don't remove unless you know what you're doing */
  587. udelay(1000);
  588. }
  589. /* we could compute the total bogomips here, but why bother?,
  590. * Code added from smpboot.c */
  591. {
  592. unsigned long bogosum = 0;
  593. for (i = 0; i < NR_CPUS; i++)
  594. if (cpu_isset(i, cpu_online_map))
  595. bogosum += cpu_data(i).loops_per_jiffy;
  596. printk(KERN_INFO "Total of %d processors activated "
  597. "(%lu.%02lu BogoMIPS).\n",
  598. cpucount + 1, bogosum / (500000 / HZ),
  599. (bogosum / (5000 / HZ)) % 100);
  600. }
  601. voyager_extended_cpus = hweight32(voyager_extended_vic_processors);
  602. printk("VOYAGER: Extended (interrupt handling CPUs): "
  603. "%d, non-extended: %d\n", voyager_extended_cpus,
  604. num_booting_cpus() - voyager_extended_cpus);
  605. /* that's it, switch to symmetric mode */
  606. outb(0, VIC_PRIORITY_REGISTER);
  607. outb(0, VIC_CLAIM_REGISTER_0);
  608. outb(0, VIC_CLAIM_REGISTER_1);
  609. VDEBUG(("VOYAGER SMP: Booted with %d CPUs\n", num_booting_cpus()));
  610. }
  611. /* Reload the secondary CPUs task structure (this function does not
  612. * return ) */
  613. void __init initialize_secondary(void)
  614. {
  615. #if 0
  616. // AC kernels only
  617. set_current(hard_get_current());
  618. #endif
  619. /*
  620. * We don't actually need to load the full TSS,
  621. * basically just the stack pointer and the eip.
  622. */
  623. asm volatile ("movl %0,%%esp\n\t"
  624. "jmp *%1"::"r" (current->thread.esp),
  625. "r"(current->thread.eip));
  626. }
  627. /* handle a Voyager SYS_INT -- If we don't, the base board will
  628. * panic the system.
  629. *
  630. * System interrupts occur because some problem was detected on the
  631. * various busses. To find out what you have to probe all the
  632. * hardware via the CAT bus. FIXME: At the moment we do nothing. */
  633. fastcall void smp_vic_sys_interrupt(struct pt_regs *regs)
  634. {
  635. ack_CPI(VIC_SYS_INT);
  636. printk("Voyager SYSTEM INTERRUPT\n");
  637. }
  638. /* Handle a voyager CMN_INT; These interrupts occur either because of
  639. * a system status change or because a single bit memory error
  640. * occurred. FIXME: At the moment, ignore all this. */
  641. fastcall void smp_vic_cmn_interrupt(struct pt_regs *regs)
  642. {
  643. static __u8 in_cmn_int = 0;
  644. static DEFINE_SPINLOCK(cmn_int_lock);
  645. /* common ints are broadcast, so make sure we only do this once */
  646. _raw_spin_lock(&cmn_int_lock);
  647. if (in_cmn_int)
  648. goto unlock_end;
  649. in_cmn_int++;
  650. _raw_spin_unlock(&cmn_int_lock);
  651. VDEBUG(("Voyager COMMON INTERRUPT\n"));
  652. if (voyager_level == 5)
  653. voyager_cat_do_common_interrupt();
  654. _raw_spin_lock(&cmn_int_lock);
  655. in_cmn_int = 0;
  656. unlock_end:
  657. _raw_spin_unlock(&cmn_int_lock);
  658. ack_CPI(VIC_CMN_INT);
  659. }
  660. /*
  661. * Reschedule call back. Nothing to do, all the work is done
  662. * automatically when we return from the interrupt. */
  663. static void smp_reschedule_interrupt(void)
  664. {
  665. /* do nothing */
  666. }
  667. static struct mm_struct *flush_mm;
  668. static unsigned long flush_va;
  669. static DEFINE_SPINLOCK(tlbstate_lock);
  670. /*
  671. * We cannot call mmdrop() because we are in interrupt context,
  672. * instead update mm->cpu_vm_mask.
  673. *
  674. * We need to reload %cr3 since the page tables may be going
  675. * away from under us..
  676. */
  677. static inline void leave_mm(unsigned long cpu)
  678. {
  679. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
  680. BUG();
  681. cpu_clear(cpu, per_cpu(cpu_tlbstate, cpu).active_mm->cpu_vm_mask);
  682. load_cr3(swapper_pg_dir);
  683. }
  684. /*
  685. * Invalidate call-back
  686. */
  687. static void smp_invalidate_interrupt(void)
  688. {
  689. __u8 cpu = smp_processor_id();
  690. if (!test_bit(cpu, &smp_invalidate_needed))
  691. return;
  692. /* This will flood messages. Don't uncomment unless you see
  693. * Problems with cross cpu invalidation
  694. VDEBUG(("VOYAGER SMP: CPU%d received INVALIDATE_CPI\n",
  695. smp_processor_id()));
  696. */
  697. if (flush_mm == per_cpu(cpu_tlbstate, cpu).active_mm) {
  698. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK) {
  699. if (flush_va == TLB_FLUSH_ALL)
  700. local_flush_tlb();
  701. else
  702. __flush_tlb_one(flush_va);
  703. } else
  704. leave_mm(cpu);
  705. }
  706. smp_mb__before_clear_bit();
  707. clear_bit(cpu, &smp_invalidate_needed);
  708. smp_mb__after_clear_bit();
  709. }
  710. /* All the new flush operations for 2.4 */
  711. /* This routine is called with a physical cpu mask */
  712. static void
  713. voyager_flush_tlb_others(unsigned long cpumask, struct mm_struct *mm,
  714. unsigned long va)
  715. {
  716. int stuck = 50000;
  717. if (!cpumask)
  718. BUG();
  719. if ((cpumask & cpus_addr(cpu_online_map)[0]) != cpumask)
  720. BUG();
  721. if (cpumask & (1 << smp_processor_id()))
  722. BUG();
  723. if (!mm)
  724. BUG();
  725. spin_lock(&tlbstate_lock);
  726. flush_mm = mm;
  727. flush_va = va;
  728. atomic_set_mask(cpumask, &smp_invalidate_needed);
  729. /*
  730. * We have to send the CPI only to
  731. * CPUs affected.
  732. */
  733. send_CPI(cpumask, VIC_INVALIDATE_CPI);
  734. while (smp_invalidate_needed) {
  735. mb();
  736. if (--stuck == 0) {
  737. printk("***WARNING*** Stuck doing invalidate CPI "
  738. "(CPU%d)\n", smp_processor_id());
  739. break;
  740. }
  741. }
  742. /* Uncomment only to debug invalidation problems
  743. VDEBUG(("VOYAGER SMP: Completed invalidate CPI (CPU%d)\n", cpu));
  744. */
  745. flush_mm = NULL;
  746. flush_va = 0;
  747. spin_unlock(&tlbstate_lock);
  748. }
  749. void flush_tlb_current_task(void)
  750. {
  751. struct mm_struct *mm = current->mm;
  752. unsigned long cpu_mask;
  753. preempt_disable();
  754. cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
  755. local_flush_tlb();
  756. if (cpu_mask)
  757. voyager_flush_tlb_others(cpu_mask, mm, TLB_FLUSH_ALL);
  758. preempt_enable();
  759. }
  760. void flush_tlb_mm(struct mm_struct *mm)
  761. {
  762. unsigned long cpu_mask;
  763. preempt_disable();
  764. cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
  765. if (current->active_mm == mm) {
  766. if (current->mm)
  767. local_flush_tlb();
  768. else
  769. leave_mm(smp_processor_id());
  770. }
  771. if (cpu_mask)
  772. voyager_flush_tlb_others(cpu_mask, mm, TLB_FLUSH_ALL);
  773. preempt_enable();
  774. }
  775. void flush_tlb_page(struct vm_area_struct *vma, unsigned long va)
  776. {
  777. struct mm_struct *mm = vma->vm_mm;
  778. unsigned long cpu_mask;
  779. preempt_disable();
  780. cpu_mask = cpus_addr(mm->cpu_vm_mask)[0] & ~(1 << smp_processor_id());
  781. if (current->active_mm == mm) {
  782. if (current->mm)
  783. __flush_tlb_one(va);
  784. else
  785. leave_mm(smp_processor_id());
  786. }
  787. if (cpu_mask)
  788. voyager_flush_tlb_others(cpu_mask, mm, va);
  789. preempt_enable();
  790. }
  791. EXPORT_SYMBOL(flush_tlb_page);
  792. /* enable the requested IRQs */
  793. static void smp_enable_irq_interrupt(void)
  794. {
  795. __u8 irq;
  796. __u8 cpu = get_cpu();
  797. VDEBUG(("VOYAGER SMP: CPU%d enabling irq mask 0x%x\n", cpu,
  798. vic_irq_enable_mask[cpu]));
  799. spin_lock(&vic_irq_lock);
  800. for (irq = 0; irq < 16; irq++) {
  801. if (vic_irq_enable_mask[cpu] & (1 << irq))
  802. enable_local_vic_irq(irq);
  803. }
  804. vic_irq_enable_mask[cpu] = 0;
  805. spin_unlock(&vic_irq_lock);
  806. put_cpu_no_resched();
  807. }
  808. /*
  809. * CPU halt call-back
  810. */
  811. static void smp_stop_cpu_function(void *dummy)
  812. {
  813. VDEBUG(("VOYAGER SMP: CPU%d is STOPPING\n", smp_processor_id()));
  814. cpu_clear(smp_processor_id(), cpu_online_map);
  815. local_irq_disable();
  816. for (;;)
  817. halt();
  818. }
  819. static DEFINE_SPINLOCK(call_lock);
  820. struct call_data_struct {
  821. void (*func) (void *info);
  822. void *info;
  823. volatile unsigned long started;
  824. volatile unsigned long finished;
  825. int wait;
  826. };
  827. static struct call_data_struct *call_data;
  828. /* execute a thread on a new CPU. The function to be called must be
  829. * previously set up. This is used to schedule a function for
  830. * execution on all CPUs - set up the function then broadcast a
  831. * function_interrupt CPI to come here on each CPU */
  832. static void smp_call_function_interrupt(void)
  833. {
  834. void (*func) (void *info) = call_data->func;
  835. void *info = call_data->info;
  836. /* must take copy of wait because call_data may be replaced
  837. * unless the function is waiting for us to finish */
  838. int wait = call_data->wait;
  839. __u8 cpu = smp_processor_id();
  840. /*
  841. * Notify initiating CPU that I've grabbed the data and am
  842. * about to execute the function
  843. */
  844. mb();
  845. if (!test_and_clear_bit(cpu, &call_data->started)) {
  846. /* If the bit wasn't set, this could be a replay */
  847. printk(KERN_WARNING "VOYAGER SMP: CPU %d received call funtion"
  848. " with no call pending\n", cpu);
  849. return;
  850. }
  851. /*
  852. * At this point the info structure may be out of scope unless wait==1
  853. */
  854. irq_enter();
  855. (*func) (info);
  856. __get_cpu_var(irq_stat).irq_call_count++;
  857. irq_exit();
  858. if (wait) {
  859. mb();
  860. clear_bit(cpu, &call_data->finished);
  861. }
  862. }
  863. static int
  864. voyager_smp_call_function_mask(cpumask_t cpumask,
  865. void (*func) (void *info), void *info, int wait)
  866. {
  867. struct call_data_struct data;
  868. u32 mask = cpus_addr(cpumask)[0];
  869. mask &= ~(1 << smp_processor_id());
  870. if (!mask)
  871. return 0;
  872. /* Can deadlock when called with interrupts disabled */
  873. WARN_ON(irqs_disabled());
  874. data.func = func;
  875. data.info = info;
  876. data.started = mask;
  877. data.wait = wait;
  878. if (wait)
  879. data.finished = mask;
  880. spin_lock(&call_lock);
  881. call_data = &data;
  882. wmb();
  883. /* Send a message to all other CPUs and wait for them to respond */
  884. send_CPI(mask, VIC_CALL_FUNCTION_CPI);
  885. /* Wait for response */
  886. while (data.started)
  887. barrier();
  888. if (wait)
  889. while (data.finished)
  890. barrier();
  891. spin_unlock(&call_lock);
  892. return 0;
  893. }
  894. /* Sorry about the name. In an APIC based system, the APICs
  895. * themselves are programmed to send a timer interrupt. This is used
  896. * by linux to reschedule the processor. Voyager doesn't have this,
  897. * so we use the system clock to interrupt one processor, which in
  898. * turn, broadcasts a timer CPI to all the others --- we receive that
  899. * CPI here. We don't use this actually for counting so losing
  900. * ticks doesn't matter
  901. *
  902. * FIXME: For those CPUs which actually have a local APIC, we could
  903. * try to use it to trigger this interrupt instead of having to
  904. * broadcast the timer tick. Unfortunately, all my pentium DYADs have
  905. * no local APIC, so I can't do this
  906. *
  907. * This function is currently a placeholder and is unused in the code */
  908. fastcall void smp_apic_timer_interrupt(struct pt_regs *regs)
  909. {
  910. struct pt_regs *old_regs = set_irq_regs(regs);
  911. wrapper_smp_local_timer_interrupt();
  912. set_irq_regs(old_regs);
  913. }
  914. /* All of the QUAD interrupt GATES */
  915. fastcall void smp_qic_timer_interrupt(struct pt_regs *regs)
  916. {
  917. struct pt_regs *old_regs = set_irq_regs(regs);
  918. ack_QIC_CPI(QIC_TIMER_CPI);
  919. wrapper_smp_local_timer_interrupt();
  920. set_irq_regs(old_regs);
  921. }
  922. fastcall void smp_qic_invalidate_interrupt(struct pt_regs *regs)
  923. {
  924. ack_QIC_CPI(QIC_INVALIDATE_CPI);
  925. smp_invalidate_interrupt();
  926. }
  927. fastcall void smp_qic_reschedule_interrupt(struct pt_regs *regs)
  928. {
  929. ack_QIC_CPI(QIC_RESCHEDULE_CPI);
  930. smp_reschedule_interrupt();
  931. }
  932. fastcall void smp_qic_enable_irq_interrupt(struct pt_regs *regs)
  933. {
  934. ack_QIC_CPI(QIC_ENABLE_IRQ_CPI);
  935. smp_enable_irq_interrupt();
  936. }
  937. fastcall void smp_qic_call_function_interrupt(struct pt_regs *regs)
  938. {
  939. ack_QIC_CPI(QIC_CALL_FUNCTION_CPI);
  940. smp_call_function_interrupt();
  941. }
  942. fastcall void smp_vic_cpi_interrupt(struct pt_regs *regs)
  943. {
  944. struct pt_regs *old_regs = set_irq_regs(regs);
  945. __u8 cpu = smp_processor_id();
  946. if (is_cpu_quad())
  947. ack_QIC_CPI(VIC_CPI_LEVEL0);
  948. else
  949. ack_VIC_CPI(VIC_CPI_LEVEL0);
  950. if (test_and_clear_bit(VIC_TIMER_CPI, &vic_cpi_mailbox[cpu]))
  951. wrapper_smp_local_timer_interrupt();
  952. if (test_and_clear_bit(VIC_INVALIDATE_CPI, &vic_cpi_mailbox[cpu]))
  953. smp_invalidate_interrupt();
  954. if (test_and_clear_bit(VIC_RESCHEDULE_CPI, &vic_cpi_mailbox[cpu]))
  955. smp_reschedule_interrupt();
  956. if (test_and_clear_bit(VIC_ENABLE_IRQ_CPI, &vic_cpi_mailbox[cpu]))
  957. smp_enable_irq_interrupt();
  958. if (test_and_clear_bit(VIC_CALL_FUNCTION_CPI, &vic_cpi_mailbox[cpu]))
  959. smp_call_function_interrupt();
  960. set_irq_regs(old_regs);
  961. }
  962. static void do_flush_tlb_all(void *info)
  963. {
  964. unsigned long cpu = smp_processor_id();
  965. __flush_tlb_all();
  966. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_LAZY)
  967. leave_mm(cpu);
  968. }
  969. /* flush the TLB of every active CPU in the system */
  970. void flush_tlb_all(void)
  971. {
  972. on_each_cpu(do_flush_tlb_all, 0, 1, 1);
  973. }
  974. /* used to set up the trampoline for other CPUs when the memory manager
  975. * is sorted out */
  976. void __init smp_alloc_memory(void)
  977. {
  978. trampoline_base = (__u32) alloc_bootmem_low_pages(PAGE_SIZE);
  979. if (__pa(trampoline_base) >= 0x93000)
  980. BUG();
  981. }
  982. /* send a reschedule CPI to one CPU by physical CPU number*/
  983. static void voyager_smp_send_reschedule(int cpu)
  984. {
  985. send_one_CPI(cpu, VIC_RESCHEDULE_CPI);
  986. }
  987. int hard_smp_processor_id(void)
  988. {
  989. __u8 i;
  990. __u8 cpumask = inb(VIC_PROC_WHO_AM_I);
  991. if ((cpumask & QUAD_IDENTIFIER) == QUAD_IDENTIFIER)
  992. return cpumask & 0x1F;
  993. for (i = 0; i < 8; i++) {
  994. if (cpumask & (1 << i))
  995. return i;
  996. }
  997. printk("** WARNING ** Illegal cpuid returned by VIC: %d", cpumask);
  998. return 0;
  999. }
  1000. int safe_smp_processor_id(void)
  1001. {
  1002. return hard_smp_processor_id();
  1003. }
  1004. /* broadcast a halt to all other CPUs */
  1005. static void voyager_smp_send_stop(void)
  1006. {
  1007. smp_call_function(smp_stop_cpu_function, NULL, 1, 1);
  1008. }
  1009. /* this function is triggered in time.c when a clock tick fires
  1010. * we need to re-broadcast the tick to all CPUs */
  1011. void smp_vic_timer_interrupt(void)
  1012. {
  1013. send_CPI_allbutself(VIC_TIMER_CPI);
  1014. smp_local_timer_interrupt();
  1015. }
  1016. /* local (per CPU) timer interrupt. It does both profiling and
  1017. * process statistics/rescheduling.
  1018. *
  1019. * We do profiling in every local tick, statistics/rescheduling
  1020. * happen only every 'profiling multiplier' ticks. The default
  1021. * multiplier is 1 and it can be changed by writing the new multiplier
  1022. * value into /proc/profile.
  1023. */
  1024. void smp_local_timer_interrupt(void)
  1025. {
  1026. int cpu = smp_processor_id();
  1027. long weight;
  1028. profile_tick(CPU_PROFILING);
  1029. if (--per_cpu(prof_counter, cpu) <= 0) {
  1030. /*
  1031. * The multiplier may have changed since the last time we got
  1032. * to this point as a result of the user writing to
  1033. * /proc/profile. In this case we need to adjust the APIC
  1034. * timer accordingly.
  1035. *
  1036. * Interrupts are already masked off at this point.
  1037. */
  1038. per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
  1039. if (per_cpu(prof_counter, cpu) !=
  1040. per_cpu(prof_old_multiplier, cpu)) {
  1041. /* FIXME: need to update the vic timer tick here */
  1042. per_cpu(prof_old_multiplier, cpu) =
  1043. per_cpu(prof_counter, cpu);
  1044. }
  1045. update_process_times(user_mode_vm(get_irq_regs()));
  1046. }
  1047. if (((1 << cpu) & voyager_extended_vic_processors) == 0)
  1048. /* only extended VIC processors participate in
  1049. * interrupt distribution */
  1050. return;
  1051. /*
  1052. * We take the 'long' return path, and there every subsystem
  1053. * grabs the appropriate locks (kernel lock/ irq lock).
  1054. *
  1055. * we might want to decouple profiling from the 'long path',
  1056. * and do the profiling totally in assembly.
  1057. *
  1058. * Currently this isn't too much of an issue (performance wise),
  1059. * we can take more than 100K local irqs per second on a 100 MHz P5.
  1060. */
  1061. if ((++vic_tick[cpu] & 0x7) != 0)
  1062. return;
  1063. /* get here every 16 ticks (about every 1/6 of a second) */
  1064. /* Change our priority to give someone else a chance at getting
  1065. * the IRQ. The algorithm goes like this:
  1066. *
  1067. * In the VIC, the dynamically routed interrupt is always
  1068. * handled by the lowest priority eligible (i.e. receiving
  1069. * interrupts) CPU. If >1 eligible CPUs are equal lowest, the
  1070. * lowest processor number gets it.
  1071. *
  1072. * The priority of a CPU is controlled by a special per-CPU
  1073. * VIC priority register which is 3 bits wide 0 being lowest
  1074. * and 7 highest priority..
  1075. *
  1076. * Therefore we subtract the average number of interrupts from
  1077. * the number we've fielded. If this number is negative, we
  1078. * lower the activity count and if it is positive, we raise
  1079. * it.
  1080. *
  1081. * I'm afraid this still leads to odd looking interrupt counts:
  1082. * the totals are all roughly equal, but the individual ones
  1083. * look rather skewed.
  1084. *
  1085. * FIXME: This algorithm is total crap when mixed with SMP
  1086. * affinity code since we now try to even up the interrupt
  1087. * counts when an affinity binding is keeping them on a
  1088. * particular CPU*/
  1089. weight = (vic_intr_count[cpu] * voyager_extended_cpus
  1090. - vic_intr_total) >> 4;
  1091. weight += 4;
  1092. if (weight > 7)
  1093. weight = 7;
  1094. if (weight < 0)
  1095. weight = 0;
  1096. outb((__u8) weight, VIC_PRIORITY_REGISTER);
  1097. #ifdef VOYAGER_DEBUG
  1098. if ((vic_tick[cpu] & 0xFFF) == 0) {
  1099. /* print this message roughly every 25 secs */
  1100. printk("VOYAGER SMP: vic_tick[%d] = %lu, weight = %ld\n",
  1101. cpu, vic_tick[cpu], weight);
  1102. }
  1103. #endif
  1104. }
  1105. /* setup the profiling timer */
  1106. int setup_profiling_timer(unsigned int multiplier)
  1107. {
  1108. int i;
  1109. if ((!multiplier))
  1110. return -EINVAL;
  1111. /*
  1112. * Set the new multiplier for each CPU. CPUs don't start using the
  1113. * new values until the next timer interrupt in which they do process
  1114. * accounting.
  1115. */
  1116. for (i = 0; i < NR_CPUS; ++i)
  1117. per_cpu(prof_multiplier, i) = multiplier;
  1118. return 0;
  1119. }
  1120. /* This is a bit of a mess, but forced on us by the genirq changes
  1121. * there's no genirq handler that really does what voyager wants
  1122. * so hack it up with the simple IRQ handler */
  1123. static void fastcall handle_vic_irq(unsigned int irq, struct irq_desc *desc)
  1124. {
  1125. before_handle_vic_irq(irq);
  1126. handle_simple_irq(irq, desc);
  1127. after_handle_vic_irq(irq);
  1128. }
  1129. /* The CPIs are handled in the per cpu 8259s, so they must be
  1130. * enabled to be received: FIX: enabling the CPIs in the early
  1131. * boot sequence interferes with bug checking; enable them later
  1132. * on in smp_init */
  1133. #define VIC_SET_GATE(cpi, vector) \
  1134. set_intr_gate((cpi) + VIC_DEFAULT_CPI_BASE, (vector))
  1135. #define QIC_SET_GATE(cpi, vector) \
  1136. set_intr_gate((cpi) + QIC_DEFAULT_CPI_BASE, (vector))
  1137. void __init smp_intr_init(void)
  1138. {
  1139. int i;
  1140. /* initialize the per cpu irq mask to all disabled */
  1141. for (i = 0; i < NR_CPUS; i++)
  1142. vic_irq_mask[i] = 0xFFFF;
  1143. VIC_SET_GATE(VIC_CPI_LEVEL0, vic_cpi_interrupt);
  1144. VIC_SET_GATE(VIC_SYS_INT, vic_sys_interrupt);
  1145. VIC_SET_GATE(VIC_CMN_INT, vic_cmn_interrupt);
  1146. QIC_SET_GATE(QIC_TIMER_CPI, qic_timer_interrupt);
  1147. QIC_SET_GATE(QIC_INVALIDATE_CPI, qic_invalidate_interrupt);
  1148. QIC_SET_GATE(QIC_RESCHEDULE_CPI, qic_reschedule_interrupt);
  1149. QIC_SET_GATE(QIC_ENABLE_IRQ_CPI, qic_enable_irq_interrupt);
  1150. QIC_SET_GATE(QIC_CALL_FUNCTION_CPI, qic_call_function_interrupt);
  1151. /* now put the VIC descriptor into the first 48 IRQs
  1152. *
  1153. * This is for later: first 16 correspond to PC IRQs; next 16
  1154. * are Primary MC IRQs and final 16 are Secondary MC IRQs */
  1155. for (i = 0; i < 48; i++)
  1156. set_irq_chip_and_handler(i, &vic_chip, handle_vic_irq);
  1157. }
  1158. /* send a CPI at level cpi to a set of cpus in cpuset (set 1 bit per
  1159. * processor to receive CPI */
  1160. static void send_CPI(__u32 cpuset, __u8 cpi)
  1161. {
  1162. int cpu;
  1163. __u32 quad_cpuset = (cpuset & voyager_quad_processors);
  1164. if (cpi < VIC_START_FAKE_CPI) {
  1165. /* fake CPI are only used for booting, so send to the
  1166. * extended quads as well---Quads must be VIC booted */
  1167. outb((__u8) (cpuset), VIC_CPI_Registers[cpi]);
  1168. return;
  1169. }
  1170. if (quad_cpuset)
  1171. send_QIC_CPI(quad_cpuset, cpi);
  1172. cpuset &= ~quad_cpuset;
  1173. cpuset &= 0xff; /* only first 8 CPUs vaild for VIC CPI */
  1174. if (cpuset == 0)
  1175. return;
  1176. for_each_online_cpu(cpu) {
  1177. if (cpuset & (1 << cpu))
  1178. set_bit(cpi, &vic_cpi_mailbox[cpu]);
  1179. }
  1180. if (cpuset)
  1181. outb((__u8) cpuset, VIC_CPI_Registers[VIC_CPI_LEVEL0]);
  1182. }
  1183. /* Acknowledge receipt of CPI in the QIC, clear in QIC hardware and
  1184. * set the cache line to shared by reading it.
  1185. *
  1186. * DON'T make this inline otherwise the cache line read will be
  1187. * optimised away
  1188. * */
  1189. static int ack_QIC_CPI(__u8 cpi)
  1190. {
  1191. __u8 cpu = hard_smp_processor_id();
  1192. cpi &= 7;
  1193. outb(1 << cpi, QIC_INTERRUPT_CLEAR1);
  1194. return voyager_quad_cpi_addr[cpu]->qic_cpi[cpi].cpi;
  1195. }
  1196. static void ack_special_QIC_CPI(__u8 cpi)
  1197. {
  1198. switch (cpi) {
  1199. case VIC_CMN_INT:
  1200. outb(QIC_CMN_INT, QIC_INTERRUPT_CLEAR0);
  1201. break;
  1202. case VIC_SYS_INT:
  1203. outb(QIC_SYS_INT, QIC_INTERRUPT_CLEAR0);
  1204. break;
  1205. }
  1206. /* also clear at the VIC, just in case (nop for non-extended proc) */
  1207. ack_VIC_CPI(cpi);
  1208. }
  1209. /* Acknowledge receipt of CPI in the VIC (essentially an EOI) */
  1210. static void ack_VIC_CPI(__u8 cpi)
  1211. {
  1212. #ifdef VOYAGER_DEBUG
  1213. unsigned long flags;
  1214. __u16 isr;
  1215. __u8 cpu = smp_processor_id();
  1216. local_irq_save(flags);
  1217. isr = vic_read_isr();
  1218. if ((isr & (1 << (cpi & 7))) == 0) {
  1219. printk("VOYAGER SMP: CPU%d lost CPI%d\n", cpu, cpi);
  1220. }
  1221. #endif
  1222. /* send specific EOI; the two system interrupts have
  1223. * bit 4 set for a separate vector but behave as the
  1224. * corresponding 3 bit intr */
  1225. outb_p(0x60 | (cpi & 7), 0x20);
  1226. #ifdef VOYAGER_DEBUG
  1227. if ((vic_read_isr() & (1 << (cpi & 7))) != 0) {
  1228. printk("VOYAGER SMP: CPU%d still asserting CPI%d\n", cpu, cpi);
  1229. }
  1230. local_irq_restore(flags);
  1231. #endif
  1232. }
  1233. /* cribbed with thanks from irq.c */
  1234. #define __byte(x,y) (((unsigned char *)&(y))[x])
  1235. #define cached_21(cpu) (__byte(0,vic_irq_mask[cpu]))
  1236. #define cached_A1(cpu) (__byte(1,vic_irq_mask[cpu]))
  1237. static unsigned int startup_vic_irq(unsigned int irq)
  1238. {
  1239. unmask_vic_irq(irq);
  1240. return 0;
  1241. }
  1242. /* The enable and disable routines. This is where we run into
  1243. * conflicting architectural philosophy. Fundamentally, the voyager
  1244. * architecture does not expect to have to disable interrupts globally
  1245. * (the IRQ controllers belong to each CPU). The processor masquerade
  1246. * which is used to start the system shouldn't be used in a running OS
  1247. * since it will cause great confusion if two separate CPUs drive to
  1248. * the same IRQ controller (I know, I've tried it).
  1249. *
  1250. * The solution is a variant on the NCR lazy SPL design:
  1251. *
  1252. * 1) To disable an interrupt, do nothing (other than set the
  1253. * IRQ_DISABLED flag). This dares the interrupt actually to arrive.
  1254. *
  1255. * 2) If the interrupt dares to come in, raise the local mask against
  1256. * it (this will result in all the CPU masks being raised
  1257. * eventually).
  1258. *
  1259. * 3) To enable the interrupt, lower the mask on the local CPU and
  1260. * broadcast an Interrupt enable CPI which causes all other CPUs to
  1261. * adjust their masks accordingly. */
  1262. static void unmask_vic_irq(unsigned int irq)
  1263. {
  1264. /* linux doesn't to processor-irq affinity, so enable on
  1265. * all CPUs we know about */
  1266. int cpu = smp_processor_id(), real_cpu;
  1267. __u16 mask = (1 << irq);
  1268. __u32 processorList = 0;
  1269. unsigned long flags;
  1270. VDEBUG(("VOYAGER: unmask_vic_irq(%d) CPU%d affinity 0x%lx\n",
  1271. irq, cpu, cpu_irq_affinity[cpu]));
  1272. spin_lock_irqsave(&vic_irq_lock, flags);
  1273. for_each_online_cpu(real_cpu) {
  1274. if (!(voyager_extended_vic_processors & (1 << real_cpu)))
  1275. continue;
  1276. if (!(cpu_irq_affinity[real_cpu] & mask)) {
  1277. /* irq has no affinity for this CPU, ignore */
  1278. continue;
  1279. }
  1280. if (real_cpu == cpu) {
  1281. enable_local_vic_irq(irq);
  1282. } else if (vic_irq_mask[real_cpu] & mask) {
  1283. vic_irq_enable_mask[real_cpu] |= mask;
  1284. processorList |= (1 << real_cpu);
  1285. }
  1286. }
  1287. spin_unlock_irqrestore(&vic_irq_lock, flags);
  1288. if (processorList)
  1289. send_CPI(processorList, VIC_ENABLE_IRQ_CPI);
  1290. }
  1291. static void mask_vic_irq(unsigned int irq)
  1292. {
  1293. /* lazy disable, do nothing */
  1294. }
  1295. static void enable_local_vic_irq(unsigned int irq)
  1296. {
  1297. __u8 cpu = smp_processor_id();
  1298. __u16 mask = ~(1 << irq);
  1299. __u16 old_mask = vic_irq_mask[cpu];
  1300. vic_irq_mask[cpu] &= mask;
  1301. if (vic_irq_mask[cpu] == old_mask)
  1302. return;
  1303. VDEBUG(("VOYAGER DEBUG: Enabling irq %d in hardware on CPU %d\n",
  1304. irq, cpu));
  1305. if (irq & 8) {
  1306. outb_p(cached_A1(cpu), 0xA1);
  1307. (void)inb_p(0xA1);
  1308. } else {
  1309. outb_p(cached_21(cpu), 0x21);
  1310. (void)inb_p(0x21);
  1311. }
  1312. }
  1313. static void disable_local_vic_irq(unsigned int irq)
  1314. {
  1315. __u8 cpu = smp_processor_id();
  1316. __u16 mask = (1 << irq);
  1317. __u16 old_mask = vic_irq_mask[cpu];
  1318. if (irq == 7)
  1319. return;
  1320. vic_irq_mask[cpu] |= mask;
  1321. if (old_mask == vic_irq_mask[cpu])
  1322. return;
  1323. VDEBUG(("VOYAGER DEBUG: Disabling irq %d in hardware on CPU %d\n",
  1324. irq, cpu));
  1325. if (irq & 8) {
  1326. outb_p(cached_A1(cpu), 0xA1);
  1327. (void)inb_p(0xA1);
  1328. } else {
  1329. outb_p(cached_21(cpu), 0x21);
  1330. (void)inb_p(0x21);
  1331. }
  1332. }
  1333. /* The VIC is level triggered, so the ack can only be issued after the
  1334. * interrupt completes. However, we do Voyager lazy interrupt
  1335. * handling here: It is an extremely expensive operation to mask an
  1336. * interrupt in the vic, so we merely set a flag (IRQ_DISABLED). If
  1337. * this interrupt actually comes in, then we mask and ack here to push
  1338. * the interrupt off to another CPU */
  1339. static void before_handle_vic_irq(unsigned int irq)
  1340. {
  1341. irq_desc_t *desc = irq_desc + irq;
  1342. __u8 cpu = smp_processor_id();
  1343. _raw_spin_lock(&vic_irq_lock);
  1344. vic_intr_total++;
  1345. vic_intr_count[cpu]++;
  1346. if (!(cpu_irq_affinity[cpu] & (1 << irq))) {
  1347. /* The irq is not in our affinity mask, push it off
  1348. * onto another CPU */
  1349. VDEBUG(("VOYAGER DEBUG: affinity triggered disable of irq %d "
  1350. "on cpu %d\n", irq, cpu));
  1351. disable_local_vic_irq(irq);
  1352. /* set IRQ_INPROGRESS to prevent the handler in irq.c from
  1353. * actually calling the interrupt routine */
  1354. desc->status |= IRQ_REPLAY | IRQ_INPROGRESS;
  1355. } else if (desc->status & IRQ_DISABLED) {
  1356. /* Damn, the interrupt actually arrived, do the lazy
  1357. * disable thing. The interrupt routine in irq.c will
  1358. * not handle a IRQ_DISABLED interrupt, so nothing more
  1359. * need be done here */
  1360. VDEBUG(("VOYAGER DEBUG: lazy disable of irq %d on CPU %d\n",
  1361. irq, cpu));
  1362. disable_local_vic_irq(irq);
  1363. desc->status |= IRQ_REPLAY;
  1364. } else {
  1365. desc->status &= ~IRQ_REPLAY;
  1366. }
  1367. _raw_spin_unlock(&vic_irq_lock);
  1368. }
  1369. /* Finish the VIC interrupt: basically mask */
  1370. static void after_handle_vic_irq(unsigned int irq)
  1371. {
  1372. irq_desc_t *desc = irq_desc + irq;
  1373. _raw_spin_lock(&vic_irq_lock);
  1374. {
  1375. unsigned int status = desc->status & ~IRQ_INPROGRESS;
  1376. #ifdef VOYAGER_DEBUG
  1377. __u16 isr;
  1378. #endif
  1379. desc->status = status;
  1380. if ((status & IRQ_DISABLED))
  1381. disable_local_vic_irq(irq);
  1382. #ifdef VOYAGER_DEBUG
  1383. /* DEBUG: before we ack, check what's in progress */
  1384. isr = vic_read_isr();
  1385. if ((isr & (1 << irq) && !(status & IRQ_REPLAY)) == 0) {
  1386. int i;
  1387. __u8 cpu = smp_processor_id();
  1388. __u8 real_cpu;
  1389. int mask; /* Um... initialize me??? --RR */
  1390. printk("VOYAGER SMP: CPU%d lost interrupt %d\n",
  1391. cpu, irq);
  1392. for_each_possible_cpu(real_cpu, mask) {
  1393. outb(VIC_CPU_MASQUERADE_ENABLE | real_cpu,
  1394. VIC_PROCESSOR_ID);
  1395. isr = vic_read_isr();
  1396. if (isr & (1 << irq)) {
  1397. printk
  1398. ("VOYAGER SMP: CPU%d ack irq %d\n",
  1399. real_cpu, irq);
  1400. ack_vic_irq(irq);
  1401. }
  1402. outb(cpu, VIC_PROCESSOR_ID);
  1403. }
  1404. }
  1405. #endif /* VOYAGER_DEBUG */
  1406. /* as soon as we ack, the interrupt is eligible for
  1407. * receipt by another CPU so everything must be in
  1408. * order here */
  1409. ack_vic_irq(irq);
  1410. if (status & IRQ_REPLAY) {
  1411. /* replay is set if we disable the interrupt
  1412. * in the before_handle_vic_irq() routine, so
  1413. * clear the in progress bit here to allow the
  1414. * next CPU to handle this correctly */
  1415. desc->status &= ~(IRQ_REPLAY | IRQ_INPROGRESS);
  1416. }
  1417. #ifdef VOYAGER_DEBUG
  1418. isr = vic_read_isr();
  1419. if ((isr & (1 << irq)) != 0)
  1420. printk("VOYAGER SMP: after_handle_vic_irq() after "
  1421. "ack irq=%d, isr=0x%x\n", irq, isr);
  1422. #endif /* VOYAGER_DEBUG */
  1423. }
  1424. _raw_spin_unlock(&vic_irq_lock);
  1425. /* All code after this point is out of the main path - the IRQ
  1426. * may be intercepted by another CPU if reasserted */
  1427. }
  1428. /* Linux processor - interrupt affinity manipulations.
  1429. *
  1430. * For each processor, we maintain a 32 bit irq affinity mask.
  1431. * Initially it is set to all 1's so every processor accepts every
  1432. * interrupt. In this call, we change the processor's affinity mask:
  1433. *
  1434. * Change from enable to disable:
  1435. *
  1436. * If the interrupt ever comes in to the processor, we will disable it
  1437. * and ack it to push it off to another CPU, so just accept the mask here.
  1438. *
  1439. * Change from disable to enable:
  1440. *
  1441. * change the mask and then do an interrupt enable CPI to re-enable on
  1442. * the selected processors */
  1443. void set_vic_irq_affinity(unsigned int irq, cpumask_t mask)
  1444. {
  1445. /* Only extended processors handle interrupts */
  1446. unsigned long real_mask;
  1447. unsigned long irq_mask = 1 << irq;
  1448. int cpu;
  1449. real_mask = cpus_addr(mask)[0] & voyager_extended_vic_processors;
  1450. if (cpus_addr(mask)[0] == 0)
  1451. /* can't have no CPUs to accept the interrupt -- extremely
  1452. * bad things will happen */
  1453. return;
  1454. if (irq == 0)
  1455. /* can't change the affinity of the timer IRQ. This
  1456. * is due to the constraint in the voyager
  1457. * architecture that the CPI also comes in on and IRQ
  1458. * line and we have chosen IRQ0 for this. If you
  1459. * raise the mask on this interrupt, the processor
  1460. * will no-longer be able to accept VIC CPIs */
  1461. return;
  1462. if (irq >= 32)
  1463. /* You can only have 32 interrupts in a voyager system
  1464. * (and 32 only if you have a secondary microchannel
  1465. * bus) */
  1466. return;
  1467. for_each_online_cpu(cpu) {
  1468. unsigned long cpu_mask = 1 << cpu;
  1469. if (cpu_mask & real_mask) {
  1470. /* enable the interrupt for this cpu */
  1471. cpu_irq_affinity[cpu] |= irq_mask;
  1472. } else {
  1473. /* disable the interrupt for this cpu */
  1474. cpu_irq_affinity[cpu] &= ~irq_mask;
  1475. }
  1476. }
  1477. /* this is magic, we now have the correct affinity maps, so
  1478. * enable the interrupt. This will send an enable CPI to
  1479. * those CPUs who need to enable it in their local masks,
  1480. * causing them to correct for the new affinity . If the
  1481. * interrupt is currently globally disabled, it will simply be
  1482. * disabled again as it comes in (voyager lazy disable). If
  1483. * the affinity map is tightened to disable the interrupt on a
  1484. * cpu, it will be pushed off when it comes in */
  1485. unmask_vic_irq(irq);
  1486. }
  1487. static void ack_vic_irq(unsigned int irq)
  1488. {
  1489. if (irq & 8) {
  1490. outb(0x62, 0x20); /* Specific EOI to cascade */
  1491. outb(0x60 | (irq & 7), 0xA0);
  1492. } else {
  1493. outb(0x60 | (irq & 7), 0x20);
  1494. }
  1495. }
  1496. /* enable the CPIs. In the VIC, the CPIs are delivered by the 8259
  1497. * but are not vectored by it. This means that the 8259 mask must be
  1498. * lowered to receive them */
  1499. static __init void vic_enable_cpi(void)
  1500. {
  1501. __u8 cpu = smp_processor_id();
  1502. /* just take a copy of the current mask (nop for boot cpu) */
  1503. vic_irq_mask[cpu] = vic_irq_mask[boot_cpu_id];
  1504. enable_local_vic_irq(VIC_CPI_LEVEL0);
  1505. enable_local_vic_irq(VIC_CPI_LEVEL1);
  1506. /* for sys int and cmn int */
  1507. enable_local_vic_irq(7);
  1508. if (is_cpu_quad()) {
  1509. outb(QIC_DEFAULT_MASK0, QIC_MASK_REGISTER0);
  1510. outb(QIC_CPI_ENABLE, QIC_MASK_REGISTER1);
  1511. VDEBUG(("VOYAGER SMP: QIC ENABLE CPI: CPU%d: MASK 0x%x\n",
  1512. cpu, QIC_CPI_ENABLE));
  1513. }
  1514. VDEBUG(("VOYAGER SMP: ENABLE CPI: CPU%d: MASK 0x%x\n",
  1515. cpu, vic_irq_mask[cpu]));
  1516. }
  1517. void voyager_smp_dump()
  1518. {
  1519. int old_cpu = smp_processor_id(), cpu;
  1520. /* dump the interrupt masks of each processor */
  1521. for_each_online_cpu(cpu) {
  1522. __u16 imr, isr, irr;
  1523. unsigned long flags;
  1524. local_irq_save(flags);
  1525. outb(VIC_CPU_MASQUERADE_ENABLE | cpu, VIC_PROCESSOR_ID);
  1526. imr = (inb(0xa1) << 8) | inb(0x21);
  1527. outb(0x0a, 0xa0);
  1528. irr = inb(0xa0) << 8;
  1529. outb(0x0a, 0x20);
  1530. irr |= inb(0x20);
  1531. outb(0x0b, 0xa0);
  1532. isr = inb(0xa0) << 8;
  1533. outb(0x0b, 0x20);
  1534. isr |= inb(0x20);
  1535. outb(old_cpu, VIC_PROCESSOR_ID);
  1536. local_irq_restore(flags);
  1537. printk("\tCPU%d: mask=0x%x, IMR=0x%x, IRR=0x%x, ISR=0x%x\n",
  1538. cpu, vic_irq_mask[cpu], imr, irr, isr);
  1539. #if 0
  1540. /* These lines are put in to try to unstick an un ack'd irq */
  1541. if (isr != 0) {
  1542. int irq;
  1543. for (irq = 0; irq < 16; irq++) {
  1544. if (isr & (1 << irq)) {
  1545. printk("\tCPU%d: ack irq %d\n",
  1546. cpu, irq);
  1547. local_irq_save(flags);
  1548. outb(VIC_CPU_MASQUERADE_ENABLE | cpu,
  1549. VIC_PROCESSOR_ID);
  1550. ack_vic_irq(irq);
  1551. outb(old_cpu, VIC_PROCESSOR_ID);
  1552. local_irq_restore(flags);
  1553. }
  1554. }
  1555. }
  1556. #endif
  1557. }
  1558. }
  1559. void smp_voyager_power_off(void *dummy)
  1560. {
  1561. if (smp_processor_id() == boot_cpu_id)
  1562. voyager_power_off();
  1563. else
  1564. smp_stop_cpu_function(NULL);
  1565. }
  1566. static void __init voyager_smp_prepare_cpus(unsigned int max_cpus)
  1567. {
  1568. /* FIXME: ignore max_cpus for now */
  1569. smp_boot_cpus();
  1570. }
  1571. static void __cpuinit voyager_smp_prepare_boot_cpu(void)
  1572. {
  1573. init_gdt(smp_processor_id());
  1574. switch_to_new_gdt();
  1575. cpu_set(smp_processor_id(), cpu_online_map);
  1576. cpu_set(smp_processor_id(), cpu_callout_map);
  1577. cpu_set(smp_processor_id(), cpu_possible_map);
  1578. cpu_set(smp_processor_id(), cpu_present_map);
  1579. }
  1580. static int __cpuinit voyager_cpu_up(unsigned int cpu)
  1581. {
  1582. /* This only works at boot for x86. See "rewrite" above. */
  1583. if (cpu_isset(cpu, smp_commenced_mask))
  1584. return -ENOSYS;
  1585. /* In case one didn't come up */
  1586. if (!cpu_isset(cpu, cpu_callin_map))
  1587. return -EIO;
  1588. /* Unleash the CPU! */
  1589. cpu_set(cpu, smp_commenced_mask);
  1590. while (!cpu_isset(cpu, cpu_online_map))
  1591. mb();
  1592. return 0;
  1593. }
  1594. static void __init voyager_smp_cpus_done(unsigned int max_cpus)
  1595. {
  1596. zap_low_mappings();
  1597. }
  1598. void __init smp_setup_processor_id(void)
  1599. {
  1600. current_thread_info()->cpu = hard_smp_processor_id();
  1601. x86_write_percpu(cpu_number, hard_smp_processor_id());
  1602. }
  1603. struct smp_ops smp_ops = {
  1604. .smp_prepare_boot_cpu = voyager_smp_prepare_boot_cpu,
  1605. .smp_prepare_cpus = voyager_smp_prepare_cpus,
  1606. .cpu_up = voyager_cpu_up,
  1607. .smp_cpus_done = voyager_smp_cpus_done,
  1608. .smp_send_stop = voyager_smp_send_stop,
  1609. .smp_send_reschedule = voyager_smp_send_reschedule,
  1610. .smp_call_function_mask = voyager_smp_call_function_mask,
  1611. };