voyager_smp.c 50 KB

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