voyager_smp.c 50 KB

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