voyager_smp.c 52 KB

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