voyager_smp.c 51 KB

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