voyager_smp.c 53 KB

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