voyager_smp.c 51 KB

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