voyager_smp.c 52 KB

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