voyager_smp.c 51 KB

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