voyager_smp.c 50 KB

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