io_apic_32.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037
  1. /*
  2. * Intel IO-APIC support for multi-Pentium hosts.
  3. *
  4. * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar, Hajnalka Szabo
  5. *
  6. * Many thanks to Stig Venaas for trying out countless experimental
  7. * patches and reporting/debugging problems patiently!
  8. *
  9. * (c) 1999, Multiple IO-APIC support, developed by
  10. * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
  11. * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
  12. * further tested and cleaned up by Zach Brown <zab@redhat.com>
  13. * and Ingo Molnar <mingo@redhat.com>
  14. *
  15. * Fixes
  16. * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
  17. * thanks to Eric Gilmore
  18. * and Rolf G. Tews
  19. * for testing these extensively
  20. * Paul Diefenbaugh : Added full ACPI support
  21. */
  22. #include <linux/mm.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/sched.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/mc146818rtc.h>
  29. #include <linux/compiler.h>
  30. #include <linux/acpi.h>
  31. #include <linux/module.h>
  32. #include <linux/sysdev.h>
  33. #include <linux/pci.h>
  34. #include <linux/msi.h>
  35. #include <linux/htirq.h>
  36. #include <linux/freezer.h>
  37. #include <linux/kthread.h>
  38. #include <linux/jiffies.h> /* time_after() */
  39. #include <asm/io.h>
  40. #include <asm/smp.h>
  41. #include <asm/desc.h>
  42. #include <asm/timer.h>
  43. #include <asm/i8259.h>
  44. #include <asm/nmi.h>
  45. #include <asm/msidef.h>
  46. #include <asm/hypertransport.h>
  47. #include <asm/setup.h>
  48. #include <mach_ipi.h>
  49. #include <mach_apic.h>
  50. #include <mach_apicdef.h>
  51. #define __apicdebuginit(type) static type __init
  52. int (*ioapic_renumber_irq)(int ioapic, int irq);
  53. atomic_t irq_mis_count;
  54. /* Where if anywhere is the i8259 connect in external int mode */
  55. static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
  56. static DEFINE_SPINLOCK(ioapic_lock);
  57. static DEFINE_SPINLOCK(vector_lock);
  58. int timer_through_8259 __initdata;
  59. /*
  60. * Is the SiS APIC rmw bug present ?
  61. * -1 = don't know, 0 = no, 1 = yes
  62. */
  63. int sis_apic_bug = -1;
  64. int first_free_entry;
  65. /*
  66. * # of IRQ routing registers
  67. */
  68. int nr_ioapic_registers[MAX_IO_APICS];
  69. /* I/O APIC entries */
  70. struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
  71. int nr_ioapics;
  72. /* MP IRQ source entries */
  73. struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
  74. /* # of MP IRQ source entries */
  75. int mp_irq_entries;
  76. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  77. int mp_bus_id_to_type[MAX_MP_BUSSES];
  78. #endif
  79. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  80. static int disable_timer_pin_1 __initdata;
  81. struct irq_cfg;
  82. struct irq_pin_list;
  83. struct irq_cfg {
  84. unsigned int irq;
  85. struct irq_cfg *next;
  86. struct irq_pin_list *irq_2_pin;
  87. cpumask_t domain;
  88. cpumask_t old_domain;
  89. unsigned move_cleanup_count;
  90. u8 vector;
  91. u8 move_in_progress : 1;
  92. };
  93. /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
  94. static struct irq_cfg irq_cfg_legacy[] __initdata = {
  95. [0] = { .irq = 0, .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, },
  96. [1] = { .irq = 1, .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, },
  97. [2] = { .irq = 2, .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, },
  98. [3] = { .irq = 3, .domain = CPU_MASK_ALL, .vector = IRQ3_VECTOR, },
  99. [4] = { .irq = 4, .domain = CPU_MASK_ALL, .vector = IRQ4_VECTOR, },
  100. [5] = { .irq = 5, .domain = CPU_MASK_ALL, .vector = IRQ5_VECTOR, },
  101. [6] = { .irq = 6, .domain = CPU_MASK_ALL, .vector = IRQ6_VECTOR, },
  102. [7] = { .irq = 7, .domain = CPU_MASK_ALL, .vector = IRQ7_VECTOR, },
  103. [8] = { .irq = 8, .domain = CPU_MASK_ALL, .vector = IRQ8_VECTOR, },
  104. [9] = { .irq = 9, .domain = CPU_MASK_ALL, .vector = IRQ9_VECTOR, },
  105. [10] = { .irq = 10, .domain = CPU_MASK_ALL, .vector = IRQ10_VECTOR, },
  106. [11] = { .irq = 11, .domain = CPU_MASK_ALL, .vector = IRQ11_VECTOR, },
  107. [12] = { .irq = 12, .domain = CPU_MASK_ALL, .vector = IRQ12_VECTOR, },
  108. [13] = { .irq = 13, .domain = CPU_MASK_ALL, .vector = IRQ13_VECTOR, },
  109. [14] = { .irq = 14, .domain = CPU_MASK_ALL, .vector = IRQ14_VECTOR, },
  110. [15] = { .irq = 15, .domain = CPU_MASK_ALL, .vector = IRQ15_VECTOR, },
  111. };
  112. static struct irq_cfg irq_cfg_init = { .irq = -1U, };
  113. /* need to be biger than size of irq_cfg_legacy */
  114. static int nr_irq_cfg = 32;
  115. static int __init parse_nr_irq_cfg(char *arg)
  116. {
  117. if (arg) {
  118. nr_irq_cfg = simple_strtoul(arg, NULL, 0);
  119. if (nr_irq_cfg < 32)
  120. nr_irq_cfg = 32;
  121. }
  122. return 0;
  123. }
  124. early_param("nr_irq_cfg", parse_nr_irq_cfg);
  125. static void init_one_irq_cfg(struct irq_cfg *cfg)
  126. {
  127. memcpy(cfg, &irq_cfg_init, sizeof(struct irq_cfg));
  128. }
  129. static struct irq_cfg *irq_cfgx;
  130. static struct irq_cfg *irq_cfgx_free;
  131. static void __init init_work(void *data)
  132. {
  133. struct dyn_array *da = data;
  134. struct irq_cfg *cfg;
  135. int legacy_count;
  136. int i;
  137. cfg = *da->name;
  138. memcpy(cfg, irq_cfg_legacy, sizeof(irq_cfg_legacy));
  139. legacy_count = sizeof(irq_cfg_legacy)/sizeof(irq_cfg_legacy[0]);
  140. for (i = legacy_count; i < *da->nr; i++)
  141. init_one_irq_cfg(&cfg[i]);
  142. for (i = 1; i < *da->nr; i++)
  143. cfg[i-1].next = &cfg[i];
  144. irq_cfgx_free = &irq_cfgx[legacy_count];
  145. irq_cfgx[legacy_count - 1].next = NULL;
  146. }
  147. #define for_each_irq_cfg(cfg) \
  148. for (cfg = irq_cfgx; cfg; cfg = cfg->next)
  149. DEFINE_DYN_ARRAY(irq_cfgx, sizeof(struct irq_cfg), nr_irq_cfg, PAGE_SIZE, init_work);
  150. static struct irq_cfg *irq_cfg(unsigned int irq)
  151. {
  152. struct irq_cfg *cfg;
  153. cfg = irq_cfgx;
  154. while (cfg) {
  155. if (cfg->irq == irq)
  156. return cfg;
  157. cfg = cfg->next;
  158. }
  159. return NULL;
  160. }
  161. static struct irq_cfg *irq_cfg_alloc(unsigned int irq)
  162. {
  163. struct irq_cfg *cfg, *cfg_pri;
  164. int i;
  165. int count = 0;
  166. cfg_pri = cfg = irq_cfgx;
  167. while (cfg) {
  168. if (cfg->irq == irq)
  169. return cfg;
  170. cfg_pri = cfg;
  171. cfg = cfg->next;
  172. count++;
  173. }
  174. if (!irq_cfgx_free) {
  175. unsigned long phys;
  176. unsigned long total_bytes;
  177. /*
  178. * we run out of pre-allocate ones, allocate more
  179. */
  180. printk(KERN_DEBUG "try to get more irq_cfg %d\n", nr_irq_cfg);
  181. total_bytes = sizeof(struct irq_cfg) * nr_irq_cfg;
  182. if (after_bootmem)
  183. cfg = kzalloc(total_bytes, GFP_ATOMIC);
  184. else
  185. cfg = __alloc_bootmem_nopanic(total_bytes, PAGE_SIZE, 0);
  186. if (!cfg)
  187. panic("please boot with nr_irq_cfg= %d\n", count * 2);
  188. phys = __pa(cfg);
  189. printk(KERN_DEBUG "irq_irq ==> [%#lx - %#lx]\n", phys, phys + total_bytes);
  190. for (i = 0; i < nr_irq_cfg; i++)
  191. init_one_irq_cfg(&cfg[i]);
  192. for (i = 1; i < nr_irq_cfg; i++)
  193. cfg[i-1].next = &cfg[i];
  194. irq_cfgx_free = cfg;
  195. }
  196. cfg = irq_cfgx_free;
  197. irq_cfgx_free = irq_cfgx_free->next;
  198. cfg->next = NULL;
  199. if (cfg_pri)
  200. cfg_pri->next = cfg;
  201. else
  202. irq_cfgx = cfg;
  203. cfg->irq = irq;
  204. printk(KERN_DEBUG "found new irq_cfg for irq %d\n", cfg->irq);
  205. #ifdef CONFIG_HAVE_SPARSE_IRQ_DEBUG
  206. {
  207. /* dump the results */
  208. struct irq_cfg *cfg;
  209. unsigned long phys;
  210. unsigned long bytes = sizeof(struct irq_cfg);
  211. printk(KERN_DEBUG "=========================== %d\n", irq);
  212. printk(KERN_DEBUG "irq_cfg dump after get that for %d\n", irq);
  213. for_each_irq_cfg(cfg) {
  214. phys = __pa(cfg);
  215. printk(KERN_DEBUG "irq_cfg %d ==> [%#lx - %#lx]\n", cfg->irq, phys, phys + bytes);
  216. }
  217. printk(KERN_DEBUG "===========================\n");
  218. }
  219. #endif
  220. return cfg;
  221. }
  222. static int assign_irq_vector(int irq, cpumask_t mask);
  223. /*
  224. * Rough estimation of how many shared IRQs there are, can
  225. * be changed anytime.
  226. */
  227. int pin_map_size;
  228. /*
  229. * This is performance-critical, we want to do it O(1)
  230. *
  231. * the indexing order of this array favors 1:1 mappings
  232. * between pins and IRQs.
  233. */
  234. struct irq_pin_list {
  235. int apic, pin;
  236. struct irq_pin_list *next;
  237. };
  238. static struct irq_pin_list *irq_2_pin_head;
  239. /* fill one page ? */
  240. static int nr_irq_2_pin = 0x100;
  241. static struct irq_pin_list *irq_2_pin_ptr;
  242. static void __init irq_2_pin_init_work(void *data)
  243. {
  244. struct dyn_array *da = data;
  245. struct irq_pin_list *pin;
  246. int i;
  247. pin = *da->name;
  248. for (i = 1; i < *da->nr; i++)
  249. pin[i-1].next = &pin[i];
  250. irq_2_pin_ptr = &pin[0];
  251. }
  252. DEFINE_DYN_ARRAY(irq_2_pin_head, sizeof(struct irq_pin_list), nr_irq_2_pin, PAGE_SIZE, irq_2_pin_init_work);
  253. static struct irq_pin_list *get_one_free_irq_2_pin(void)
  254. {
  255. struct irq_pin_list *pin;
  256. int i;
  257. pin = irq_2_pin_ptr;
  258. if (pin) {
  259. irq_2_pin_ptr = pin->next;
  260. pin->next = NULL;
  261. return pin;
  262. }
  263. /*
  264. * we run out of pre-allocate ones, allocate more
  265. */
  266. printk(KERN_DEBUG "try to get more irq_2_pin %d\n", nr_irq_2_pin);
  267. if (after_bootmem)
  268. pin = kzalloc(sizeof(struct irq_pin_list)*nr_irq_2_pin,
  269. GFP_ATOMIC);
  270. else
  271. pin = __alloc_bootmem_nopanic(sizeof(struct irq_pin_list) *
  272. nr_irq_2_pin, PAGE_SIZE, 0);
  273. if (!pin)
  274. panic("can not get more irq_2_pin\n");
  275. for (i = 1; i < nr_irq_2_pin; i++)
  276. pin[i-1].next = &pin[i];
  277. irq_2_pin_ptr = pin->next;
  278. pin->next = NULL;
  279. return pin;
  280. }
  281. struct io_apic {
  282. unsigned int index;
  283. unsigned int unused[3];
  284. unsigned int data;
  285. };
  286. static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
  287. {
  288. return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
  289. + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK);
  290. }
  291. static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
  292. {
  293. struct io_apic __iomem *io_apic = io_apic_base(apic);
  294. writel(reg, &io_apic->index);
  295. return readl(&io_apic->data);
  296. }
  297. static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
  298. {
  299. struct io_apic __iomem *io_apic = io_apic_base(apic);
  300. writel(reg, &io_apic->index);
  301. writel(value, &io_apic->data);
  302. }
  303. /*
  304. * Re-write a value: to be used for read-modify-write
  305. * cycles where the read already set up the index register.
  306. *
  307. * Older SiS APIC requires we rewrite the index register
  308. */
  309. static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
  310. {
  311. volatile struct io_apic __iomem *io_apic = io_apic_base(apic);
  312. if (sis_apic_bug)
  313. writel(reg, &io_apic->index);
  314. writel(value, &io_apic->data);
  315. }
  316. union entry_union {
  317. struct { u32 w1, w2; };
  318. struct IO_APIC_route_entry entry;
  319. };
  320. static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
  321. {
  322. union entry_union eu;
  323. unsigned long flags;
  324. spin_lock_irqsave(&ioapic_lock, flags);
  325. eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
  326. eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
  327. spin_unlock_irqrestore(&ioapic_lock, flags);
  328. return eu.entry;
  329. }
  330. /*
  331. * When we write a new IO APIC routing entry, we need to write the high
  332. * word first! If the mask bit in the low word is clear, we will enable
  333. * the interrupt, and we need to make sure the entry is fully populated
  334. * before that happens.
  335. */
  336. static void
  337. __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  338. {
  339. union entry_union eu;
  340. eu.entry = e;
  341. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  342. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  343. }
  344. static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  345. {
  346. unsigned long flags;
  347. spin_lock_irqsave(&ioapic_lock, flags);
  348. __ioapic_write_entry(apic, pin, e);
  349. spin_unlock_irqrestore(&ioapic_lock, flags);
  350. }
  351. /*
  352. * When we mask an IO APIC routing entry, we need to write the low
  353. * word first, in order to set the mask bit before we change the
  354. * high bits!
  355. */
  356. static void ioapic_mask_entry(int apic, int pin)
  357. {
  358. unsigned long flags;
  359. union entry_union eu = { .entry.mask = 1 };
  360. spin_lock_irqsave(&ioapic_lock, flags);
  361. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  362. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  363. spin_unlock_irqrestore(&ioapic_lock, flags);
  364. }
  365. #ifdef CONFIG_SMP
  366. static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector)
  367. {
  368. int apic, pin;
  369. struct irq_cfg *cfg;
  370. struct irq_pin_list *entry;
  371. cfg = irq_cfg(irq);
  372. entry = cfg->irq_2_pin;
  373. for (;;) {
  374. unsigned int reg;
  375. if (!entry)
  376. break;
  377. apic = entry->apic;
  378. pin = entry->pin;
  379. io_apic_write(apic, 0x11 + pin*2, dest);
  380. reg = io_apic_read(apic, 0x10 + pin*2);
  381. reg &= ~IO_APIC_REDIR_VECTOR_MASK;
  382. reg |= vector;
  383. io_apic_modify(apic, 0x10 + pin *2, reg);
  384. if (!entry->next)
  385. break;
  386. entry = entry->next;
  387. }
  388. }
  389. static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask)
  390. {
  391. struct irq_cfg *cfg;
  392. unsigned long flags;
  393. unsigned int dest;
  394. cpumask_t tmp;
  395. cfg = irq_cfg(irq);
  396. cpus_and(tmp, mask, cpu_online_map);
  397. if (cpus_empty(tmp))
  398. return;
  399. if (assign_irq_vector(irq, mask))
  400. return;
  401. cpus_and(tmp, cfg->domain, mask);
  402. dest = cpu_mask_to_apicid(tmp);
  403. /*
  404. * Only the high 8 bits are valid.
  405. */
  406. dest = SET_APIC_LOGICAL_ID(dest);
  407. spin_lock_irqsave(&ioapic_lock, flags);
  408. __target_IO_APIC_irq(irq, dest, cfg->vector);
  409. irq_to_desc(irq)->affinity = mask;
  410. spin_unlock_irqrestore(&ioapic_lock, flags);
  411. }
  412. #endif /* CONFIG_SMP */
  413. /*
  414. * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
  415. * shared ISA-space IRQs, so we have to support them. We are super
  416. * fast in the common case, and fast for shared ISA-space IRQs.
  417. */
  418. static void add_pin_to_irq(unsigned int irq, int apic, int pin)
  419. {
  420. struct irq_cfg *cfg;
  421. struct irq_pin_list *entry;
  422. /* first time to refer irq_cfg, so with new */
  423. cfg = irq_cfg_alloc(irq);
  424. entry = cfg->irq_2_pin;
  425. if (!entry) {
  426. entry = get_one_free_irq_2_pin();
  427. cfg->irq_2_pin = entry;
  428. entry->apic = apic;
  429. entry->pin = pin;
  430. printk(KERN_DEBUG " 0 add_pin_to_irq: irq %d --> apic %d pin %d\n", irq, apic, pin);
  431. return;
  432. }
  433. while (entry->next) {
  434. /* not again, please */
  435. if (entry->apic == apic && entry->pin == pin)
  436. return;
  437. entry = entry->next;
  438. }
  439. entry->next = get_one_free_irq_2_pin();
  440. entry = entry->next;
  441. entry->apic = apic;
  442. entry->pin = pin;
  443. printk(KERN_DEBUG " x add_pin_to_irq: irq %d --> apic %d pin %d\n", irq, apic, pin);
  444. }
  445. /*
  446. * Reroute an IRQ to a different pin.
  447. */
  448. static void __init replace_pin_at_irq(unsigned int irq,
  449. int oldapic, int oldpin,
  450. int newapic, int newpin)
  451. {
  452. struct irq_cfg *cfg = irq_cfg(irq);
  453. struct irq_pin_list *entry = cfg->irq_2_pin;
  454. int replaced = 0;
  455. while (entry) {
  456. if (entry->apic == oldapic && entry->pin == oldpin) {
  457. entry->apic = newapic;
  458. entry->pin = newpin;
  459. replaced = 1;
  460. /* every one is different, right? */
  461. break;
  462. }
  463. entry = entry->next;
  464. }
  465. /* why? call replace before add? */
  466. if (!replaced)
  467. add_pin_to_irq(irq, newapic, newpin);
  468. }
  469. static void __modify_IO_APIC_irq(unsigned int irq, unsigned long enable, unsigned long disable)
  470. {
  471. struct irq_cfg *cfg;
  472. struct irq_pin_list *entry;
  473. unsigned int pin, reg;
  474. cfg = irq_cfg(irq);
  475. entry = cfg->irq_2_pin;
  476. for (;;) {
  477. if (!entry)
  478. break;
  479. pin = entry->pin;
  480. reg = io_apic_read(entry->apic, 0x10 + pin*2);
  481. reg &= ~disable;
  482. reg |= enable;
  483. io_apic_modify(entry->apic, 0x10 + pin*2, reg);
  484. if (!entry->next)
  485. break;
  486. entry = entry->next;
  487. }
  488. }
  489. /* mask = 1 */
  490. static void __mask_IO_APIC_irq(unsigned int irq)
  491. {
  492. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, 0);
  493. }
  494. /* mask = 0 */
  495. static void __unmask_IO_APIC_irq(unsigned int irq)
  496. {
  497. __modify_IO_APIC_irq(irq, 0, IO_APIC_REDIR_MASKED);
  498. }
  499. /* mask = 1, trigger = 0 */
  500. static void __mask_and_edge_IO_APIC_irq(unsigned int irq)
  501. {
  502. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED,
  503. IO_APIC_REDIR_LEVEL_TRIGGER);
  504. }
  505. /* mask = 0, trigger = 1 */
  506. static void __unmask_and_level_IO_APIC_irq(unsigned int irq)
  507. {
  508. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_LEVEL_TRIGGER,
  509. IO_APIC_REDIR_MASKED);
  510. }
  511. static void mask_IO_APIC_irq(unsigned int irq)
  512. {
  513. unsigned long flags;
  514. spin_lock_irqsave(&ioapic_lock, flags);
  515. __mask_IO_APIC_irq(irq);
  516. spin_unlock_irqrestore(&ioapic_lock, flags);
  517. }
  518. static void unmask_IO_APIC_irq(unsigned int irq)
  519. {
  520. unsigned long flags;
  521. spin_lock_irqsave(&ioapic_lock, flags);
  522. __unmask_IO_APIC_irq(irq);
  523. spin_unlock_irqrestore(&ioapic_lock, flags);
  524. }
  525. static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
  526. {
  527. struct IO_APIC_route_entry entry;
  528. /* Check delivery_mode to be sure we're not clearing an SMI pin */
  529. entry = ioapic_read_entry(apic, pin);
  530. if (entry.delivery_mode == dest_SMI)
  531. return;
  532. /*
  533. * Disable it in the IO-APIC irq-routing table:
  534. */
  535. ioapic_mask_entry(apic, pin);
  536. }
  537. static void clear_IO_APIC(void)
  538. {
  539. int apic, pin;
  540. for (apic = 0; apic < nr_ioapics; apic++)
  541. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  542. clear_IO_APIC_pin(apic, pin);
  543. }
  544. #ifndef CONFIG_SMP
  545. void send_IPI_self(int vector)
  546. {
  547. unsigned int cfg;
  548. /*
  549. * Wait for idle.
  550. */
  551. apic_wait_icr_idle();
  552. cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL;
  553. /*
  554. * Send the IPI. The write to APIC_ICR fires this off.
  555. */
  556. apic_write(APIC_ICR, cfg);
  557. }
  558. #endif /* !CONFIG_SMP */
  559. /*
  560. * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
  561. * specific CPU-side IRQs.
  562. */
  563. #define MAX_PIRQS 8
  564. static int pirq_entries [MAX_PIRQS];
  565. static int pirqs_enabled;
  566. int skip_ioapic_setup;
  567. static int __init ioapic_pirq_setup(char *str)
  568. {
  569. int i, max;
  570. int ints[MAX_PIRQS+1];
  571. get_options(str, ARRAY_SIZE(ints), ints);
  572. for (i = 0; i < MAX_PIRQS; i++)
  573. pirq_entries[i] = -1;
  574. pirqs_enabled = 1;
  575. apic_printk(APIC_VERBOSE, KERN_INFO
  576. "PIRQ redirection, working around broken MP-BIOS.\n");
  577. max = MAX_PIRQS;
  578. if (ints[0] < MAX_PIRQS)
  579. max = ints[0];
  580. for (i = 0; i < max; i++) {
  581. apic_printk(APIC_VERBOSE, KERN_DEBUG
  582. "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
  583. /*
  584. * PIRQs are mapped upside down, usually.
  585. */
  586. pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
  587. }
  588. return 1;
  589. }
  590. __setup("pirq=", ioapic_pirq_setup);
  591. /*
  592. * Find the IRQ entry number of a certain pin.
  593. */
  594. static int find_irq_entry(int apic, int pin, int type)
  595. {
  596. int i;
  597. for (i = 0; i < mp_irq_entries; i++)
  598. if (mp_irqs[i].mp_irqtype == type &&
  599. (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid ||
  600. mp_irqs[i].mp_dstapic == MP_APIC_ALL) &&
  601. mp_irqs[i].mp_dstirq == pin)
  602. return i;
  603. return -1;
  604. }
  605. /*
  606. * Find the pin to which IRQ[irq] (ISA) is connected
  607. */
  608. static int __init find_isa_irq_pin(int irq, int type)
  609. {
  610. int i;
  611. for (i = 0; i < mp_irq_entries; i++) {
  612. int lbus = mp_irqs[i].mp_srcbus;
  613. if (test_bit(lbus, mp_bus_not_pci) &&
  614. (mp_irqs[i].mp_irqtype == type) &&
  615. (mp_irqs[i].mp_srcbusirq == irq))
  616. return mp_irqs[i].mp_dstirq;
  617. }
  618. return -1;
  619. }
  620. static int __init find_isa_irq_apic(int irq, int type)
  621. {
  622. int i;
  623. for (i = 0; i < mp_irq_entries; i++) {
  624. int lbus = mp_irqs[i].mp_srcbus;
  625. if (test_bit(lbus, mp_bus_not_pci) &&
  626. (mp_irqs[i].mp_irqtype == type) &&
  627. (mp_irqs[i].mp_srcbusirq == irq))
  628. break;
  629. }
  630. if (i < mp_irq_entries) {
  631. int apic;
  632. for (apic = 0; apic < nr_ioapics; apic++) {
  633. if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic)
  634. return apic;
  635. }
  636. }
  637. return -1;
  638. }
  639. /*
  640. * Find a specific PCI IRQ entry.
  641. * Not an __init, possibly needed by modules
  642. */
  643. static int pin_2_irq(int idx, int apic, int pin);
  644. int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
  645. {
  646. int apic, i, best_guess = -1;
  647. apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, "
  648. "slot:%d, pin:%d.\n", bus, slot, pin);
  649. if (test_bit(bus, mp_bus_not_pci)) {
  650. printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
  651. return -1;
  652. }
  653. for (i = 0; i < mp_irq_entries; i++) {
  654. int lbus = mp_irqs[i].mp_srcbus;
  655. for (apic = 0; apic < nr_ioapics; apic++)
  656. if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic ||
  657. mp_irqs[i].mp_dstapic == MP_APIC_ALL)
  658. break;
  659. if (!test_bit(lbus, mp_bus_not_pci) &&
  660. !mp_irqs[i].mp_irqtype &&
  661. (bus == lbus) &&
  662. (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) {
  663. int irq = pin_2_irq(i, apic, mp_irqs[i].mp_dstirq);
  664. if (!(apic || IO_APIC_IRQ(irq)))
  665. continue;
  666. if (pin == (mp_irqs[i].mp_srcbusirq & 3))
  667. return irq;
  668. /*
  669. * Use the first all-but-pin matching entry as a
  670. * best-guess fuzzy result for broken mptables.
  671. */
  672. if (best_guess < 0)
  673. best_guess = irq;
  674. }
  675. }
  676. return best_guess;
  677. }
  678. EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
  679. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  680. /*
  681. * EISA Edge/Level control register, ELCR
  682. */
  683. static int EISA_ELCR(unsigned int irq)
  684. {
  685. if (irq < 16) {
  686. unsigned int port = 0x4d0 + (irq >> 3);
  687. return (inb(port) >> (irq & 7)) & 1;
  688. }
  689. apic_printk(APIC_VERBOSE, KERN_INFO
  690. "Broken MPtable reports ISA irq %d\n", irq);
  691. return 0;
  692. }
  693. #endif
  694. /* ISA interrupts are always polarity zero edge triggered,
  695. * when listed as conforming in the MP table. */
  696. #define default_ISA_trigger(idx) (0)
  697. #define default_ISA_polarity(idx) (0)
  698. /* EISA interrupts are always polarity zero and can be edge or level
  699. * trigger depending on the ELCR value. If an interrupt is listed as
  700. * EISA conforming in the MP table, that means its trigger type must
  701. * be read in from the ELCR */
  702. #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mp_srcbusirq))
  703. #define default_EISA_polarity(idx) default_ISA_polarity(idx)
  704. /* PCI interrupts are always polarity one level triggered,
  705. * when listed as conforming in the MP table. */
  706. #define default_PCI_trigger(idx) (1)
  707. #define default_PCI_polarity(idx) (1)
  708. /* MCA interrupts are always polarity zero level triggered,
  709. * when listed as conforming in the MP table. */
  710. #define default_MCA_trigger(idx) (1)
  711. #define default_MCA_polarity(idx) default_ISA_polarity(idx)
  712. static int MPBIOS_polarity(int idx)
  713. {
  714. int bus = mp_irqs[idx].mp_srcbus;
  715. int polarity;
  716. /*
  717. * Determine IRQ line polarity (high active or low active):
  718. */
  719. switch (mp_irqs[idx].mp_irqflag & 3) {
  720. case 0: /* conforms, ie. bus-type dependent polarity */
  721. {
  722. polarity = test_bit(bus, mp_bus_not_pci)?
  723. default_ISA_polarity(idx):
  724. default_PCI_polarity(idx);
  725. break;
  726. }
  727. case 1: /* high active */
  728. {
  729. polarity = 0;
  730. break;
  731. }
  732. case 2: /* reserved */
  733. {
  734. printk(KERN_WARNING "broken BIOS!!\n");
  735. polarity = 1;
  736. break;
  737. }
  738. case 3: /* low active */
  739. {
  740. polarity = 1;
  741. break;
  742. }
  743. default: /* invalid */
  744. {
  745. printk(KERN_WARNING "broken BIOS!!\n");
  746. polarity = 1;
  747. break;
  748. }
  749. }
  750. return polarity;
  751. }
  752. static int MPBIOS_trigger(int idx)
  753. {
  754. int bus = mp_irqs[idx].mp_srcbus;
  755. int trigger;
  756. /*
  757. * Determine IRQ trigger mode (edge or level sensitive):
  758. */
  759. switch ((mp_irqs[idx].mp_irqflag>>2) & 3) {
  760. case 0: /* conforms, ie. bus-type dependent */
  761. {
  762. trigger = test_bit(bus, mp_bus_not_pci)?
  763. default_ISA_trigger(idx):
  764. default_PCI_trigger(idx);
  765. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  766. switch (mp_bus_id_to_type[bus]) {
  767. case MP_BUS_ISA: /* ISA pin */
  768. {
  769. /* set before the switch */
  770. break;
  771. }
  772. case MP_BUS_EISA: /* EISA pin */
  773. {
  774. trigger = default_EISA_trigger(idx);
  775. break;
  776. }
  777. case MP_BUS_PCI: /* PCI pin */
  778. {
  779. /* set before the switch */
  780. break;
  781. }
  782. case MP_BUS_MCA: /* MCA pin */
  783. {
  784. trigger = default_MCA_trigger(idx);
  785. break;
  786. }
  787. default:
  788. {
  789. printk(KERN_WARNING "broken BIOS!!\n");
  790. trigger = 1;
  791. break;
  792. }
  793. }
  794. #endif
  795. break;
  796. }
  797. case 1: /* edge */
  798. {
  799. trigger = 0;
  800. break;
  801. }
  802. case 2: /* reserved */
  803. {
  804. printk(KERN_WARNING "broken BIOS!!\n");
  805. trigger = 1;
  806. break;
  807. }
  808. case 3: /* level */
  809. {
  810. trigger = 1;
  811. break;
  812. }
  813. default: /* invalid */
  814. {
  815. printk(KERN_WARNING "broken BIOS!!\n");
  816. trigger = 0;
  817. break;
  818. }
  819. }
  820. return trigger;
  821. }
  822. static inline int irq_polarity(int idx)
  823. {
  824. return MPBIOS_polarity(idx);
  825. }
  826. static inline int irq_trigger(int idx)
  827. {
  828. return MPBIOS_trigger(idx);
  829. }
  830. static int pin_2_irq(int idx, int apic, int pin)
  831. {
  832. int irq, i;
  833. int bus = mp_irqs[idx].mp_srcbus;
  834. /*
  835. * Debugging check, we are in big trouble if this message pops up!
  836. */
  837. if (mp_irqs[idx].mp_dstirq != pin)
  838. printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
  839. if (test_bit(bus, mp_bus_not_pci))
  840. irq = mp_irqs[idx].mp_srcbusirq;
  841. else {
  842. /*
  843. * PCI IRQs are mapped in order
  844. */
  845. i = irq = 0;
  846. while (i < apic)
  847. irq += nr_ioapic_registers[i++];
  848. irq += pin;
  849. /*
  850. * For MPS mode, so far only needed by ES7000 platform
  851. */
  852. if (ioapic_renumber_irq)
  853. irq = ioapic_renumber_irq(apic, irq);
  854. }
  855. /*
  856. * PCI IRQ command line redirection. Yes, limits are hardcoded.
  857. */
  858. if ((pin >= 16) && (pin <= 23)) {
  859. if (pirq_entries[pin-16] != -1) {
  860. if (!pirq_entries[pin-16]) {
  861. apic_printk(APIC_VERBOSE, KERN_DEBUG
  862. "disabling PIRQ%d\n", pin-16);
  863. } else {
  864. irq = pirq_entries[pin-16];
  865. apic_printk(APIC_VERBOSE, KERN_DEBUG
  866. "using PIRQ%d -> IRQ %d\n",
  867. pin-16, irq);
  868. }
  869. }
  870. }
  871. return irq;
  872. }
  873. void lock_vector_lock(void)
  874. {
  875. /* Used to the online set of cpus does not change
  876. * during assign_irq_vector.
  877. */
  878. spin_lock(&vector_lock);
  879. }
  880. void unlock_vector_lock(void)
  881. {
  882. spin_unlock(&vector_lock);
  883. }
  884. static int __assign_irq_vector(int irq, cpumask_t mask)
  885. {
  886. static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
  887. unsigned int old_vector;
  888. int cpu;
  889. struct irq_cfg *cfg;
  890. cfg = irq_cfg(irq);
  891. /* Only try and allocate irqs on cpus that are present */
  892. cpus_and(mask, mask, cpu_online_map);
  893. if ((cfg->move_in_progress) || cfg->move_cleanup_count)
  894. return -EBUSY;
  895. old_vector = cfg->vector;
  896. if (old_vector) {
  897. cpumask_t tmp;
  898. cpus_and(tmp, cfg->domain, mask);
  899. if (!cpus_empty(tmp))
  900. return 0;
  901. }
  902. for_each_cpu_mask_nr(cpu, mask) {
  903. cpumask_t domain, new_mask;
  904. int new_cpu;
  905. int vector, offset;
  906. domain = vector_allocation_domain(cpu);
  907. cpus_and(new_mask, domain, cpu_online_map);
  908. vector = current_vector;
  909. offset = current_offset;
  910. next:
  911. vector += 8;
  912. if (vector >= first_system_vector) {
  913. /* If we run out of vectors on large boxen, must share them. */
  914. offset = (offset + 1) % 8;
  915. vector = FIRST_DEVICE_VECTOR + offset;
  916. }
  917. if (unlikely(current_vector == vector))
  918. continue;
  919. if (vector == SYSCALL_VECTOR)
  920. goto next;
  921. for_each_cpu_mask_nr(new_cpu, new_mask)
  922. if (per_cpu(vector_irq, new_cpu)[vector] != -1)
  923. goto next;
  924. /* Found one! */
  925. current_vector = vector;
  926. current_offset = offset;
  927. if (old_vector) {
  928. cfg->move_in_progress = 1;
  929. cfg->old_domain = cfg->domain;
  930. }
  931. printk(KERN_DEBUG "assign_irq_vector: irq %d vector %#x cpu ", irq, vector);
  932. for_each_cpu_mask_nr(new_cpu, new_mask) {
  933. per_cpu(vector_irq, new_cpu)[vector] = irq;
  934. printk(KERN_CONT " %d ", new_cpu);
  935. }
  936. printk(KERN_CONT "\n");
  937. cfg->vector = vector;
  938. cfg->domain = domain;
  939. return 0;
  940. }
  941. return -ENOSPC;
  942. }
  943. static int assign_irq_vector(int irq, cpumask_t mask)
  944. {
  945. int err;
  946. unsigned long flags;
  947. spin_lock_irqsave(&vector_lock, flags);
  948. err = __assign_irq_vector(irq, mask);
  949. spin_unlock_irqrestore(&vector_lock, flags);
  950. return err;
  951. }
  952. static void __clear_irq_vector(int irq)
  953. {
  954. struct irq_cfg *cfg;
  955. cpumask_t mask;
  956. int cpu, vector;
  957. cfg = irq_cfg(irq);
  958. BUG_ON(!cfg->vector);
  959. vector = cfg->vector;
  960. cpus_and(mask, cfg->domain, cpu_online_map);
  961. for_each_cpu_mask_nr(cpu, mask)
  962. per_cpu(vector_irq, cpu)[vector] = -1;
  963. cfg->vector = 0;
  964. cpus_clear(cfg->domain);
  965. }
  966. void __setup_vector_irq(int cpu)
  967. {
  968. /* Initialize vector_irq on a new cpu */
  969. /* This function must be called with vector_lock held */
  970. int irq, vector;
  971. struct irq_cfg *cfg;
  972. /* Mark the inuse vectors */
  973. for_each_irq_cfg(cfg) {
  974. if (!cpu_isset(cpu, cfg->domain))
  975. continue;
  976. vector = cfg->vector;
  977. irq = cfg->irq;
  978. per_cpu(vector_irq, cpu)[vector] = irq;
  979. }
  980. /* Mark the free vectors */
  981. for (vector = 0; vector < NR_VECTORS; ++vector) {
  982. irq = per_cpu(vector_irq, cpu)[vector];
  983. if (irq < 0)
  984. continue;
  985. cfg = irq_cfg(irq);
  986. if (!cpu_isset(cpu, cfg->domain))
  987. per_cpu(vector_irq, cpu)[vector] = -1;
  988. }
  989. }
  990. static struct irq_chip ioapic_chip;
  991. #define IOAPIC_AUTO -1
  992. #define IOAPIC_EDGE 0
  993. #define IOAPIC_LEVEL 1
  994. static inline int IO_APIC_irq_trigger(int irq)
  995. {
  996. int apic, idx, pin;
  997. for (apic = 0; apic < nr_ioapics; apic++) {
  998. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  999. idx = find_irq_entry(apic, pin, mp_INT);
  1000. if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
  1001. return irq_trigger(idx);
  1002. }
  1003. }
  1004. /*
  1005. * nonexistent IRQs are edge default
  1006. */
  1007. return 0;
  1008. }
  1009. static void ioapic_register_intr(int irq, unsigned long trigger)
  1010. {
  1011. struct irq_desc *desc;
  1012. /* first time to use this irq_desc */
  1013. if (irq < 16)
  1014. desc = irq_to_desc(irq);
  1015. else
  1016. desc = irq_to_desc_alloc(irq);
  1017. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  1018. trigger == IOAPIC_LEVEL) {
  1019. desc->status |= IRQ_LEVEL;
  1020. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1021. handle_fasteoi_irq, "fasteoi");
  1022. } else {
  1023. desc->status &= ~IRQ_LEVEL;
  1024. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1025. handle_edge_irq, "edge");
  1026. }
  1027. }
  1028. static int setup_ioapic_entry(int apic, int irq,
  1029. struct IO_APIC_route_entry *entry,
  1030. unsigned int destination, int trigger,
  1031. int polarity, int vector)
  1032. {
  1033. /*
  1034. * add it to the IO-APIC irq-routing table:
  1035. */
  1036. memset(entry,0,sizeof(*entry));
  1037. entry->delivery_mode = INT_DELIVERY_MODE;
  1038. entry->dest_mode = INT_DEST_MODE;
  1039. entry->dest = destination;
  1040. entry->mask = 0; /* enable IRQ */
  1041. entry->trigger = trigger;
  1042. entry->polarity = polarity;
  1043. entry->vector = vector;
  1044. /* Mask level triggered irqs.
  1045. * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
  1046. */
  1047. if (trigger)
  1048. entry->mask = 1;
  1049. return 0;
  1050. }
  1051. static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq,
  1052. int trigger, int polarity)
  1053. {
  1054. struct irq_cfg *cfg;
  1055. struct IO_APIC_route_entry entry;
  1056. cpumask_t mask;
  1057. if (!IO_APIC_IRQ(irq))
  1058. return;
  1059. cfg = irq_cfg(irq);
  1060. mask = TARGET_CPUS;
  1061. if (assign_irq_vector(irq, mask))
  1062. return;
  1063. cpus_and(mask, cfg->domain, mask);
  1064. apic_printk(APIC_VERBOSE,KERN_DEBUG
  1065. "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
  1066. "IRQ %d Mode:%i Active:%i)\n",
  1067. apic, mp_ioapics[apic].mp_apicid, pin, cfg->vector,
  1068. irq, trigger, polarity);
  1069. if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry,
  1070. cpu_mask_to_apicid(mask), trigger, polarity,
  1071. cfg->vector)) {
  1072. printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
  1073. mp_ioapics[apic].mp_apicid, pin);
  1074. __clear_irq_vector(irq);
  1075. return;
  1076. }
  1077. ioapic_register_intr(irq, trigger);
  1078. if (irq < 16)
  1079. disable_8259A_irq(irq);
  1080. ioapic_write_entry(apic, pin, entry);
  1081. }
  1082. static void __init setup_IO_APIC_irqs(void)
  1083. {
  1084. int apic, pin, idx, irq, first_notcon = 1;
  1085. apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
  1086. for (apic = 0; apic < nr_ioapics; apic++) {
  1087. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1088. idx = find_irq_entry(apic,pin,mp_INT);
  1089. if (idx == -1) {
  1090. if (first_notcon) {
  1091. apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mp_apicid, pin);
  1092. first_notcon = 0;
  1093. } else
  1094. apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mp_apicid, pin);
  1095. continue;
  1096. }
  1097. if (!first_notcon) {
  1098. apic_printk(APIC_VERBOSE, " not connected.\n");
  1099. first_notcon = 1;
  1100. }
  1101. irq = pin_2_irq(idx, apic, pin);
  1102. if (multi_timer_check(apic, irq))
  1103. continue;
  1104. add_pin_to_irq(irq, apic, pin);
  1105. setup_IO_APIC_irq(apic, pin, irq,
  1106. irq_trigger(idx), irq_polarity(idx));
  1107. }
  1108. }
  1109. if (!first_notcon)
  1110. apic_printk(APIC_VERBOSE, " not connected.\n");
  1111. }
  1112. /*
  1113. * Set up the timer pin, possibly with the 8259A-master behind.
  1114. */
  1115. static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin,
  1116. int vector)
  1117. {
  1118. struct IO_APIC_route_entry entry;
  1119. memset(&entry, 0, sizeof(entry));
  1120. /*
  1121. * We use logical delivery to get the timer IRQ
  1122. * to the first CPU.
  1123. */
  1124. entry.dest_mode = INT_DEST_MODE;
  1125. entry.mask = 1; /* mask IRQ now */
  1126. entry.dest = cpu_mask_to_apicid(TARGET_CPUS);
  1127. entry.delivery_mode = INT_DELIVERY_MODE;
  1128. entry.polarity = 0;
  1129. entry.trigger = 0;
  1130. entry.vector = vector;
  1131. /*
  1132. * The timer IRQ doesn't have to know that behind the
  1133. * scene we may have a 8259A-master in AEOI mode ...
  1134. */
  1135. ioapic_register_intr(0, IOAPIC_EDGE);
  1136. /*
  1137. * Add it to the IO-APIC irq-routing table:
  1138. */
  1139. ioapic_write_entry(apic, pin, entry);
  1140. }
  1141. __apicdebuginit(void) print_IO_APIC(void)
  1142. {
  1143. int apic, i;
  1144. union IO_APIC_reg_00 reg_00;
  1145. union IO_APIC_reg_01 reg_01;
  1146. union IO_APIC_reg_02 reg_02;
  1147. union IO_APIC_reg_03 reg_03;
  1148. unsigned long flags;
  1149. struct irq_cfg *cfg;
  1150. if (apic_verbosity == APIC_QUIET)
  1151. return;
  1152. printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
  1153. for (i = 0; i < nr_ioapics; i++)
  1154. printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
  1155. mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]);
  1156. /*
  1157. * We are a bit conservative about what we expect. We have to
  1158. * know about every hardware change ASAP.
  1159. */
  1160. printk(KERN_INFO "testing the IO APIC.......................\n");
  1161. for (apic = 0; apic < nr_ioapics; apic++) {
  1162. spin_lock_irqsave(&ioapic_lock, flags);
  1163. reg_00.raw = io_apic_read(apic, 0);
  1164. reg_01.raw = io_apic_read(apic, 1);
  1165. if (reg_01.bits.version >= 0x10)
  1166. reg_02.raw = io_apic_read(apic, 2);
  1167. if (reg_01.bits.version >= 0x20)
  1168. reg_03.raw = io_apic_read(apic, 3);
  1169. spin_unlock_irqrestore(&ioapic_lock, flags);
  1170. printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid);
  1171. printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
  1172. printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
  1173. printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
  1174. printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
  1175. printk(KERN_DEBUG ".... register #01: %08X\n", reg_01.raw);
  1176. printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
  1177. printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
  1178. printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
  1179. /*
  1180. * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
  1181. * but the value of reg_02 is read as the previous read register
  1182. * value, so ignore it if reg_02 == reg_01.
  1183. */
  1184. if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
  1185. printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
  1186. printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
  1187. }
  1188. /*
  1189. * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
  1190. * or reg_03, but the value of reg_0[23] is read as the previous read
  1191. * register value, so ignore it if reg_03 == reg_0[12].
  1192. */
  1193. if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
  1194. reg_03.raw != reg_01.raw) {
  1195. printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
  1196. printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
  1197. }
  1198. printk(KERN_DEBUG ".... IRQ redirection table:\n");
  1199. printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol"
  1200. " Stat Dmod Deli Vect: \n");
  1201. for (i = 0; i <= reg_01.bits.entries; i++) {
  1202. struct IO_APIC_route_entry entry;
  1203. entry = ioapic_read_entry(apic, i);
  1204. printk(KERN_DEBUG " %02x %02X ", i, entry.dest);
  1205. printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
  1206. entry.mask,
  1207. entry.trigger,
  1208. entry.irr,
  1209. entry.polarity,
  1210. entry.delivery_status,
  1211. entry.dest_mode,
  1212. entry.delivery_mode,
  1213. entry.vector
  1214. );
  1215. }
  1216. }
  1217. printk(KERN_DEBUG "IRQ to pin mappings:\n");
  1218. for_each_irq_cfg(cfg) {
  1219. struct irq_pin_list *entry = cfg->irq_2_pin;
  1220. if (!entry)
  1221. continue;
  1222. printk(KERN_DEBUG "IRQ%d ", i);
  1223. for (;;) {
  1224. printk("-> %d:%d", entry->apic, entry->pin);
  1225. if (!entry->next)
  1226. break;
  1227. entry = entry->next;
  1228. }
  1229. printk("\n");
  1230. }
  1231. printk(KERN_INFO ".................................... done.\n");
  1232. return;
  1233. }
  1234. __apicdebuginit(void) print_APIC_bitfield(int base)
  1235. {
  1236. unsigned int v;
  1237. int i, j;
  1238. if (apic_verbosity == APIC_QUIET)
  1239. return;
  1240. printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
  1241. for (i = 0; i < 8; i++) {
  1242. v = apic_read(base + i*0x10);
  1243. for (j = 0; j < 32; j++) {
  1244. if (v & (1<<j))
  1245. printk("1");
  1246. else
  1247. printk("0");
  1248. }
  1249. printk("\n");
  1250. }
  1251. }
  1252. __apicdebuginit(void) print_local_APIC(void *dummy)
  1253. {
  1254. unsigned int v, ver, maxlvt;
  1255. u64 icr;
  1256. if (apic_verbosity == APIC_QUIET)
  1257. return;
  1258. printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
  1259. smp_processor_id(), hard_smp_processor_id());
  1260. v = apic_read(APIC_ID);
  1261. printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v,
  1262. GET_APIC_ID(v));
  1263. v = apic_read(APIC_LVR);
  1264. printk(KERN_INFO "... APIC VERSION: %08x\n", v);
  1265. ver = GET_APIC_VERSION(v);
  1266. maxlvt = lapic_get_maxlvt();
  1267. v = apic_read(APIC_TASKPRI);
  1268. printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  1269. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1270. v = apic_read(APIC_ARBPRI);
  1271. printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
  1272. v & APIC_ARBPRI_MASK);
  1273. v = apic_read(APIC_PROCPRI);
  1274. printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
  1275. }
  1276. v = apic_read(APIC_EOI);
  1277. printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
  1278. v = apic_read(APIC_RRR);
  1279. printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
  1280. v = apic_read(APIC_LDR);
  1281. printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
  1282. v = apic_read(APIC_DFR);
  1283. printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
  1284. v = apic_read(APIC_SPIV);
  1285. printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
  1286. printk(KERN_DEBUG "... APIC ISR field:\n");
  1287. print_APIC_bitfield(APIC_ISR);
  1288. printk(KERN_DEBUG "... APIC TMR field:\n");
  1289. print_APIC_bitfield(APIC_TMR);
  1290. printk(KERN_DEBUG "... APIC IRR field:\n");
  1291. print_APIC_bitfield(APIC_IRR);
  1292. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1293. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  1294. apic_write(APIC_ESR, 0);
  1295. v = apic_read(APIC_ESR);
  1296. printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
  1297. }
  1298. icr = apic_icr_read();
  1299. printk(KERN_DEBUG "... APIC ICR: %08x\n", icr);
  1300. printk(KERN_DEBUG "... APIC ICR2: %08x\n", icr >> 32);
  1301. v = apic_read(APIC_LVTT);
  1302. printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
  1303. if (maxlvt > 3) { /* PC is LVT#4. */
  1304. v = apic_read(APIC_LVTPC);
  1305. printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
  1306. }
  1307. v = apic_read(APIC_LVT0);
  1308. printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
  1309. v = apic_read(APIC_LVT1);
  1310. printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
  1311. if (maxlvt > 2) { /* ERR is LVT#3. */
  1312. v = apic_read(APIC_LVTERR);
  1313. printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
  1314. }
  1315. v = apic_read(APIC_TMICT);
  1316. printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
  1317. v = apic_read(APIC_TMCCT);
  1318. printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
  1319. v = apic_read(APIC_TDCR);
  1320. printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
  1321. printk("\n");
  1322. }
  1323. __apicdebuginit(void) print_all_local_APICs(void)
  1324. {
  1325. on_each_cpu(print_local_APIC, NULL, 1);
  1326. }
  1327. __apicdebuginit(void) print_PIC(void)
  1328. {
  1329. unsigned int v;
  1330. unsigned long flags;
  1331. if (apic_verbosity == APIC_QUIET)
  1332. return;
  1333. printk(KERN_DEBUG "\nprinting PIC contents\n");
  1334. spin_lock_irqsave(&i8259A_lock, flags);
  1335. v = inb(0xa1) << 8 | inb(0x21);
  1336. printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
  1337. v = inb(0xa0) << 8 | inb(0x20);
  1338. printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
  1339. outb(0x0b, 0xa0);
  1340. outb(0x0b, 0x20);
  1341. v = inb(0xa0) << 8 | inb(0x20);
  1342. outb(0x0a, 0xa0);
  1343. outb(0x0a, 0x20);
  1344. spin_unlock_irqrestore(&i8259A_lock, flags);
  1345. printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
  1346. v = inb(0x4d1) << 8 | inb(0x4d0);
  1347. printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
  1348. }
  1349. __apicdebuginit(int) print_all_ICs(void)
  1350. {
  1351. print_PIC();
  1352. print_all_local_APICs();
  1353. print_IO_APIC();
  1354. return 0;
  1355. }
  1356. fs_initcall(print_all_ICs);
  1357. static void __init enable_IO_APIC(void)
  1358. {
  1359. union IO_APIC_reg_01 reg_01;
  1360. int i8259_apic, i8259_pin;
  1361. int i, apic;
  1362. unsigned long flags;
  1363. if (!pirqs_enabled)
  1364. for (i = 0; i < MAX_PIRQS; i++)
  1365. pirq_entries[i] = -1;
  1366. /*
  1367. * The number of IO-APIC IRQ registers (== #pins):
  1368. */
  1369. for (apic = 0; apic < nr_ioapics; apic++) {
  1370. spin_lock_irqsave(&ioapic_lock, flags);
  1371. reg_01.raw = io_apic_read(apic, 1);
  1372. spin_unlock_irqrestore(&ioapic_lock, flags);
  1373. nr_ioapic_registers[apic] = reg_01.bits.entries+1;
  1374. }
  1375. for (apic = 0; apic < nr_ioapics; apic++) {
  1376. int pin;
  1377. /* See if any of the pins is in ExtINT mode */
  1378. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1379. struct IO_APIC_route_entry entry;
  1380. entry = ioapic_read_entry(apic, pin);
  1381. /* If the interrupt line is enabled and in ExtInt mode
  1382. * I have found the pin where the i8259 is connected.
  1383. */
  1384. if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
  1385. ioapic_i8259.apic = apic;
  1386. ioapic_i8259.pin = pin;
  1387. goto found_i8259;
  1388. }
  1389. }
  1390. }
  1391. found_i8259:
  1392. /* Look to see what if the MP table has reported the ExtINT */
  1393. /* If we could not find the appropriate pin by looking at the ioapic
  1394. * the i8259 probably is not connected the ioapic but give the
  1395. * mptable a chance anyway.
  1396. */
  1397. i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
  1398. i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
  1399. /* Trust the MP table if nothing is setup in the hardware */
  1400. if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
  1401. printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
  1402. ioapic_i8259.pin = i8259_pin;
  1403. ioapic_i8259.apic = i8259_apic;
  1404. }
  1405. /* Complain if the MP table and the hardware disagree */
  1406. if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
  1407. (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
  1408. {
  1409. printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
  1410. }
  1411. /*
  1412. * Do not trust the IO-APIC being empty at bootup
  1413. */
  1414. clear_IO_APIC();
  1415. }
  1416. /*
  1417. * Not an __init, needed by the reboot code
  1418. */
  1419. void disable_IO_APIC(void)
  1420. {
  1421. /*
  1422. * Clear the IO-APIC before rebooting:
  1423. */
  1424. clear_IO_APIC();
  1425. /*
  1426. * If the i8259 is routed through an IOAPIC
  1427. * Put that IOAPIC in virtual wire mode
  1428. * so legacy interrupts can be delivered.
  1429. */
  1430. if (ioapic_i8259.pin != -1) {
  1431. struct IO_APIC_route_entry entry;
  1432. memset(&entry, 0, sizeof(entry));
  1433. entry.mask = 0; /* Enabled */
  1434. entry.trigger = 0; /* Edge */
  1435. entry.irr = 0;
  1436. entry.polarity = 0; /* High */
  1437. entry.delivery_status = 0;
  1438. entry.dest_mode = 0; /* Physical */
  1439. entry.delivery_mode = dest_ExtINT; /* ExtInt */
  1440. entry.vector = 0;
  1441. entry.dest = read_apic_id();
  1442. /*
  1443. * Add it to the IO-APIC irq-routing table:
  1444. */
  1445. ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
  1446. }
  1447. disconnect_bsp_APIC(ioapic_i8259.pin != -1);
  1448. }
  1449. /*
  1450. * function to set the IO-APIC physical IDs based on the
  1451. * values stored in the MPC table.
  1452. *
  1453. * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
  1454. */
  1455. static void __init setup_ioapic_ids_from_mpc(void)
  1456. {
  1457. union IO_APIC_reg_00 reg_00;
  1458. physid_mask_t phys_id_present_map;
  1459. int apic;
  1460. int i;
  1461. unsigned char old_id;
  1462. unsigned long flags;
  1463. if (x86_quirks->setup_ioapic_ids && x86_quirks->setup_ioapic_ids())
  1464. return;
  1465. /*
  1466. * Don't check I/O APIC IDs for xAPIC systems. They have
  1467. * no meaning without the serial APIC bus.
  1468. */
  1469. if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  1470. || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  1471. return;
  1472. /*
  1473. * This is broken; anything with a real cpu count has to
  1474. * circumvent this idiocy regardless.
  1475. */
  1476. phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map);
  1477. /*
  1478. * Set the IOAPIC ID to the value stored in the MPC table.
  1479. */
  1480. for (apic = 0; apic < nr_ioapics; apic++) {
  1481. /* Read the register 0 value */
  1482. spin_lock_irqsave(&ioapic_lock, flags);
  1483. reg_00.raw = io_apic_read(apic, 0);
  1484. spin_unlock_irqrestore(&ioapic_lock, flags);
  1485. old_id = mp_ioapics[apic].mp_apicid;
  1486. if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) {
  1487. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
  1488. apic, mp_ioapics[apic].mp_apicid);
  1489. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1490. reg_00.bits.ID);
  1491. mp_ioapics[apic].mp_apicid = reg_00.bits.ID;
  1492. }
  1493. /*
  1494. * Sanity check, is the ID really free? Every APIC in a
  1495. * system must have a unique ID or we get lots of nice
  1496. * 'stuck on smp_invalidate_needed IPI wait' messages.
  1497. */
  1498. if (check_apicid_used(phys_id_present_map,
  1499. mp_ioapics[apic].mp_apicid)) {
  1500. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
  1501. apic, mp_ioapics[apic].mp_apicid);
  1502. for (i = 0; i < get_physical_broadcast(); i++)
  1503. if (!physid_isset(i, phys_id_present_map))
  1504. break;
  1505. if (i >= get_physical_broadcast())
  1506. panic("Max APIC ID exceeded!\n");
  1507. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1508. i);
  1509. physid_set(i, phys_id_present_map);
  1510. mp_ioapics[apic].mp_apicid = i;
  1511. } else {
  1512. physid_mask_t tmp;
  1513. tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid);
  1514. apic_printk(APIC_VERBOSE, "Setting %d in the "
  1515. "phys_id_present_map\n",
  1516. mp_ioapics[apic].mp_apicid);
  1517. physids_or(phys_id_present_map, phys_id_present_map, tmp);
  1518. }
  1519. /*
  1520. * We need to adjust the IRQ routing table
  1521. * if the ID changed.
  1522. */
  1523. if (old_id != mp_ioapics[apic].mp_apicid)
  1524. for (i = 0; i < mp_irq_entries; i++)
  1525. if (mp_irqs[i].mp_dstapic == old_id)
  1526. mp_irqs[i].mp_dstapic
  1527. = mp_ioapics[apic].mp_apicid;
  1528. /*
  1529. * Read the right value from the MPC table and
  1530. * write it into the ID register.
  1531. */
  1532. apic_printk(APIC_VERBOSE, KERN_INFO
  1533. "...changing IO-APIC physical APIC ID to %d ...",
  1534. mp_ioapics[apic].mp_apicid);
  1535. reg_00.bits.ID = mp_ioapics[apic].mp_apicid;
  1536. spin_lock_irqsave(&ioapic_lock, flags);
  1537. io_apic_write(apic, 0, reg_00.raw);
  1538. spin_unlock_irqrestore(&ioapic_lock, flags);
  1539. /*
  1540. * Sanity check
  1541. */
  1542. spin_lock_irqsave(&ioapic_lock, flags);
  1543. reg_00.raw = io_apic_read(apic, 0);
  1544. spin_unlock_irqrestore(&ioapic_lock, flags);
  1545. if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid)
  1546. printk("could not set ID!\n");
  1547. else
  1548. apic_printk(APIC_VERBOSE, " ok.\n");
  1549. }
  1550. }
  1551. int no_timer_check __initdata;
  1552. static int __init notimercheck(char *s)
  1553. {
  1554. no_timer_check = 1;
  1555. return 1;
  1556. }
  1557. __setup("no_timer_check", notimercheck);
  1558. /*
  1559. * There is a nasty bug in some older SMP boards, their mptable lies
  1560. * about the timer IRQ. We do the following to work around the situation:
  1561. *
  1562. * - timer IRQ defaults to IO-APIC IRQ
  1563. * - if this function detects that timer IRQs are defunct, then we fall
  1564. * back to ISA timer IRQs
  1565. */
  1566. static int __init timer_irq_works(void)
  1567. {
  1568. unsigned long t1 = jiffies;
  1569. unsigned long flags;
  1570. if (no_timer_check)
  1571. return 1;
  1572. local_save_flags(flags);
  1573. local_irq_enable();
  1574. /* Let ten ticks pass... */
  1575. mdelay((10 * 1000) / HZ);
  1576. local_irq_restore(flags);
  1577. /*
  1578. * Expect a few ticks at least, to be sure some possible
  1579. * glue logic does not lock up after one or two first
  1580. * ticks in a non-ExtINT mode. Also the local APIC
  1581. * might have cached one ExtINT interrupt. Finally, at
  1582. * least one tick may be lost due to delays.
  1583. */
  1584. if (time_after(jiffies, t1 + 4))
  1585. return 1;
  1586. return 0;
  1587. }
  1588. /*
  1589. * In the SMP+IOAPIC case it might happen that there are an unspecified
  1590. * number of pending IRQ events unhandled. These cases are very rare,
  1591. * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
  1592. * better to do it this way as thus we do not have to be aware of
  1593. * 'pending' interrupts in the IRQ path, except at this point.
  1594. */
  1595. /*
  1596. * Edge triggered needs to resend any interrupt
  1597. * that was delayed but this is now handled in the device
  1598. * independent code.
  1599. */
  1600. /*
  1601. * Startup quirk:
  1602. *
  1603. * Starting up a edge-triggered IO-APIC interrupt is
  1604. * nasty - we need to make sure that we get the edge.
  1605. * If it is already asserted for some reason, we need
  1606. * return 1 to indicate that is was pending.
  1607. *
  1608. * This is not complete - we should be able to fake
  1609. * an edge even if it isn't on the 8259A...
  1610. *
  1611. * (We do this for level-triggered IRQs too - it cannot hurt.)
  1612. */
  1613. static unsigned int startup_ioapic_irq(unsigned int irq)
  1614. {
  1615. int was_pending = 0;
  1616. unsigned long flags;
  1617. spin_lock_irqsave(&ioapic_lock, flags);
  1618. if (irq < 16) {
  1619. disable_8259A_irq(irq);
  1620. if (i8259A_irq_pending(irq))
  1621. was_pending = 1;
  1622. }
  1623. __unmask_IO_APIC_irq(irq);
  1624. spin_unlock_irqrestore(&ioapic_lock, flags);
  1625. return was_pending;
  1626. }
  1627. static int ioapic_retrigger_irq(unsigned int irq)
  1628. {
  1629. send_IPI_self(irq_cfg(irq)->vector);
  1630. return 1;
  1631. }
  1632. #ifdef CONFIG_SMP
  1633. asmlinkage void smp_irq_move_cleanup_interrupt(void)
  1634. {
  1635. unsigned vector, me;
  1636. ack_APIC_irq();
  1637. irq_enter();
  1638. me = smp_processor_id();
  1639. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  1640. unsigned int irq;
  1641. struct irq_desc *desc;
  1642. struct irq_cfg *cfg;
  1643. irq = __get_cpu_var(vector_irq)[vector];
  1644. desc = irq_to_desc(irq);
  1645. if (!desc)
  1646. continue;
  1647. cfg = irq_cfg(irq);
  1648. spin_lock(&desc->lock);
  1649. if (!cfg->move_cleanup_count)
  1650. goto unlock;
  1651. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain))
  1652. goto unlock;
  1653. __get_cpu_var(vector_irq)[vector] = -1;
  1654. cfg->move_cleanup_count--;
  1655. unlock:
  1656. spin_unlock(&desc->lock);
  1657. }
  1658. irq_exit();
  1659. }
  1660. static void irq_complete_move(unsigned int irq)
  1661. {
  1662. struct irq_cfg *cfg = irq_cfg(irq);
  1663. unsigned vector, me;
  1664. if (likely(!cfg->move_in_progress))
  1665. return;
  1666. vector = ~get_irq_regs()->orig_ax;
  1667. me = smp_processor_id();
  1668. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) {
  1669. cpumask_t cleanup_mask;
  1670. cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map);
  1671. cfg->move_cleanup_count = cpus_weight(cleanup_mask);
  1672. send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  1673. cfg->move_in_progress = 0;
  1674. }
  1675. }
  1676. #else
  1677. static inline void irq_complete_move(unsigned int irq) {}
  1678. #endif
  1679. static void ack_apic_edge(unsigned int irq)
  1680. {
  1681. irq_complete_move(irq);
  1682. move_native_irq(irq);
  1683. ack_APIC_irq();
  1684. }
  1685. static void ack_apic_level(unsigned int irq)
  1686. {
  1687. unsigned long v;
  1688. int i;
  1689. irq_complete_move(irq);
  1690. move_native_irq(irq);
  1691. /*
  1692. * It appears there is an erratum which affects at least version 0x11
  1693. * of I/O APIC (that's the 82093AA and cores integrated into various
  1694. * chipsets). Under certain conditions a level-triggered interrupt is
  1695. * erroneously delivered as edge-triggered one but the respective IRR
  1696. * bit gets set nevertheless. As a result the I/O unit expects an EOI
  1697. * message but it will never arrive and further interrupts are blocked
  1698. * from the source. The exact reason is so far unknown, but the
  1699. * phenomenon was observed when two consecutive interrupt requests
  1700. * from a given source get delivered to the same CPU and the source is
  1701. * temporarily disabled in between.
  1702. *
  1703. * A workaround is to simulate an EOI message manually. We achieve it
  1704. * by setting the trigger mode to edge and then to level when the edge
  1705. * trigger mode gets detected in the TMR of a local APIC for a
  1706. * level-triggered interrupt. We mask the source for the time of the
  1707. * operation to prevent an edge-triggered interrupt escaping meanwhile.
  1708. * The idea is from Manfred Spraul. --macro
  1709. */
  1710. i = irq_cfg(irq)->vector;
  1711. v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
  1712. ack_APIC_irq();
  1713. if (!(v & (1 << (i & 0x1f)))) {
  1714. atomic_inc(&irq_mis_count);
  1715. spin_lock(&ioapic_lock);
  1716. __mask_and_edge_IO_APIC_irq(irq);
  1717. __unmask_and_level_IO_APIC_irq(irq);
  1718. spin_unlock(&ioapic_lock);
  1719. }
  1720. }
  1721. static struct irq_chip ioapic_chip __read_mostly = {
  1722. .name = "IO-APIC",
  1723. .startup = startup_ioapic_irq,
  1724. .mask = mask_IO_APIC_irq,
  1725. .unmask = unmask_IO_APIC_irq,
  1726. .ack = ack_apic_edge,
  1727. .eoi = ack_apic_level,
  1728. #ifdef CONFIG_SMP
  1729. .set_affinity = set_ioapic_affinity_irq,
  1730. #endif
  1731. .retrigger = ioapic_retrigger_irq,
  1732. };
  1733. static inline void init_IO_APIC_traps(void)
  1734. {
  1735. int irq;
  1736. struct irq_desc *desc;
  1737. struct irq_cfg *cfg;
  1738. /*
  1739. * NOTE! The local APIC isn't very good at handling
  1740. * multiple interrupts at the same interrupt level.
  1741. * As the interrupt level is determined by taking the
  1742. * vector number and shifting that right by 4, we
  1743. * want to spread these out a bit so that they don't
  1744. * all fall in the same interrupt level.
  1745. *
  1746. * Also, we've got to be careful not to trash gate
  1747. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  1748. */
  1749. for_each_irq_cfg(cfg) {
  1750. irq = cfg->irq;
  1751. if (IO_APIC_IRQ(irq) && !cfg->vector) {
  1752. /*
  1753. * Hmm.. We don't have an entry for this,
  1754. * so default to an old-fashioned 8259
  1755. * interrupt if we can..
  1756. */
  1757. if (irq < 16)
  1758. make_8259A_irq(irq);
  1759. else {
  1760. desc = irq_to_desc(irq);
  1761. /* Strange. Oh, well.. */
  1762. desc->chip = &no_irq_chip;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. /*
  1768. * The local APIC irq-chip implementation:
  1769. */
  1770. static void mask_lapic_irq(unsigned int irq)
  1771. {
  1772. unsigned long v;
  1773. v = apic_read(APIC_LVT0);
  1774. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  1775. }
  1776. static void unmask_lapic_irq(unsigned int irq)
  1777. {
  1778. unsigned long v;
  1779. v = apic_read(APIC_LVT0);
  1780. apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
  1781. }
  1782. static void ack_lapic_irq(unsigned int irq)
  1783. {
  1784. ack_APIC_irq();
  1785. }
  1786. static struct irq_chip lapic_chip __read_mostly = {
  1787. .name = "local-APIC",
  1788. .mask = mask_lapic_irq,
  1789. .unmask = unmask_lapic_irq,
  1790. .ack = ack_lapic_irq,
  1791. };
  1792. static void lapic_register_intr(int irq)
  1793. {
  1794. struct irq_desc *desc;
  1795. desc = irq_to_desc(irq);
  1796. desc->status &= ~IRQ_LEVEL;
  1797. set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
  1798. "edge");
  1799. }
  1800. static void __init setup_nmi(void)
  1801. {
  1802. /*
  1803. * Dirty trick to enable the NMI watchdog ...
  1804. * We put the 8259A master into AEOI mode and
  1805. * unmask on all local APICs LVT0 as NMI.
  1806. *
  1807. * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
  1808. * is from Maciej W. Rozycki - so we do not have to EOI from
  1809. * the NMI handler or the timer interrupt.
  1810. */
  1811. apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
  1812. enable_NMI_through_LVT0();
  1813. apic_printk(APIC_VERBOSE, " done.\n");
  1814. }
  1815. /*
  1816. * This looks a bit hackish but it's about the only one way of sending
  1817. * a few INTA cycles to 8259As and any associated glue logic. ICR does
  1818. * not support the ExtINT mode, unfortunately. We need to send these
  1819. * cycles as some i82489DX-based boards have glue logic that keeps the
  1820. * 8259A interrupt line asserted until INTA. --macro
  1821. */
  1822. static inline void __init unlock_ExtINT_logic(void)
  1823. {
  1824. int apic, pin, i;
  1825. struct IO_APIC_route_entry entry0, entry1;
  1826. unsigned char save_control, save_freq_select;
  1827. pin = find_isa_irq_pin(8, mp_INT);
  1828. if (pin == -1) {
  1829. WARN_ON_ONCE(1);
  1830. return;
  1831. }
  1832. apic = find_isa_irq_apic(8, mp_INT);
  1833. if (apic == -1) {
  1834. WARN_ON_ONCE(1);
  1835. return;
  1836. }
  1837. entry0 = ioapic_read_entry(apic, pin);
  1838. clear_IO_APIC_pin(apic, pin);
  1839. memset(&entry1, 0, sizeof(entry1));
  1840. entry1.dest_mode = 0; /* physical delivery */
  1841. entry1.mask = 0; /* unmask IRQ now */
  1842. entry1.dest = hard_smp_processor_id();
  1843. entry1.delivery_mode = dest_ExtINT;
  1844. entry1.polarity = entry0.polarity;
  1845. entry1.trigger = 0;
  1846. entry1.vector = 0;
  1847. ioapic_write_entry(apic, pin, entry1);
  1848. save_control = CMOS_READ(RTC_CONTROL);
  1849. save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
  1850. CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
  1851. RTC_FREQ_SELECT);
  1852. CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
  1853. i = 100;
  1854. while (i-- > 0) {
  1855. mdelay(10);
  1856. if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
  1857. i -= 10;
  1858. }
  1859. CMOS_WRITE(save_control, RTC_CONTROL);
  1860. CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
  1861. clear_IO_APIC_pin(apic, pin);
  1862. ioapic_write_entry(apic, pin, entry0);
  1863. }
  1864. /*
  1865. * This code may look a bit paranoid, but it's supposed to cooperate with
  1866. * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
  1867. * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
  1868. * fanatically on his truly buggy board.
  1869. */
  1870. static inline void __init check_timer(void)
  1871. {
  1872. struct irq_cfg *cfg = irq_cfg(0);
  1873. int apic1, pin1, apic2, pin2;
  1874. int no_pin1 = 0;
  1875. unsigned int ver;
  1876. unsigned long flags;
  1877. local_irq_save(flags);
  1878. ver = apic_read(APIC_LVR);
  1879. ver = GET_APIC_VERSION(ver);
  1880. /*
  1881. * get/set the timer IRQ vector:
  1882. */
  1883. disable_8259A_irq(0);
  1884. assign_irq_vector(0, TARGET_CPUS);
  1885. /*
  1886. * As IRQ0 is to be enabled in the 8259A, the virtual
  1887. * wire has to be disabled in the local APIC. Also
  1888. * timer interrupts need to be acknowledged manually in
  1889. * the 8259A for the i82489DX when using the NMI
  1890. * watchdog as that APIC treats NMIs as level-triggered.
  1891. * The AEOI mode will finish them in the 8259A
  1892. * automatically.
  1893. */
  1894. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  1895. init_8259A(1);
  1896. timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
  1897. pin1 = find_isa_irq_pin(0, mp_INT);
  1898. apic1 = find_isa_irq_apic(0, mp_INT);
  1899. pin2 = ioapic_i8259.pin;
  1900. apic2 = ioapic_i8259.apic;
  1901. apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
  1902. "apic1=%d pin1=%d apic2=%d pin2=%d\n",
  1903. cfg->vector, apic1, pin1, apic2, pin2);
  1904. /*
  1905. * Some BIOS writers are clueless and report the ExtINTA
  1906. * I/O APIC input from the cascaded 8259A as the timer
  1907. * interrupt input. So just in case, if only one pin
  1908. * was found above, try it both directly and through the
  1909. * 8259A.
  1910. */
  1911. if (pin1 == -1) {
  1912. pin1 = pin2;
  1913. apic1 = apic2;
  1914. no_pin1 = 1;
  1915. } else if (pin2 == -1) {
  1916. pin2 = pin1;
  1917. apic2 = apic1;
  1918. }
  1919. if (pin1 != -1) {
  1920. /*
  1921. * Ok, does IRQ0 through the IOAPIC work?
  1922. */
  1923. if (no_pin1) {
  1924. add_pin_to_irq(0, apic1, pin1);
  1925. setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
  1926. }
  1927. unmask_IO_APIC_irq(0);
  1928. if (timer_irq_works()) {
  1929. if (nmi_watchdog == NMI_IO_APIC) {
  1930. setup_nmi();
  1931. enable_8259A_irq(0);
  1932. }
  1933. if (disable_timer_pin_1 > 0)
  1934. clear_IO_APIC_pin(0, pin1);
  1935. goto out;
  1936. }
  1937. clear_IO_APIC_pin(apic1, pin1);
  1938. if (!no_pin1)
  1939. apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
  1940. "8254 timer not connected to IO-APIC\n");
  1941. apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
  1942. "(IRQ0) through the 8259A ...\n");
  1943. apic_printk(APIC_QUIET, KERN_INFO
  1944. "..... (found apic %d pin %d) ...\n", apic2, pin2);
  1945. /*
  1946. * legacy devices should be connected to IO APIC #0
  1947. */
  1948. replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
  1949. setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
  1950. unmask_IO_APIC_irq(0);
  1951. enable_8259A_irq(0);
  1952. if (timer_irq_works()) {
  1953. apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
  1954. timer_through_8259 = 1;
  1955. if (nmi_watchdog == NMI_IO_APIC) {
  1956. disable_8259A_irq(0);
  1957. setup_nmi();
  1958. enable_8259A_irq(0);
  1959. }
  1960. goto out;
  1961. }
  1962. /*
  1963. * Cleanup, just in case ...
  1964. */
  1965. disable_8259A_irq(0);
  1966. clear_IO_APIC_pin(apic2, pin2);
  1967. apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
  1968. }
  1969. if (nmi_watchdog == NMI_IO_APIC) {
  1970. apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
  1971. "through the IO-APIC - disabling NMI Watchdog!\n");
  1972. nmi_watchdog = NMI_NONE;
  1973. }
  1974. timer_ack = 0;
  1975. apic_printk(APIC_QUIET, KERN_INFO
  1976. "...trying to set up timer as Virtual Wire IRQ...\n");
  1977. lapic_register_intr(0);
  1978. apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
  1979. enable_8259A_irq(0);
  1980. if (timer_irq_works()) {
  1981. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  1982. goto out;
  1983. }
  1984. disable_8259A_irq(0);
  1985. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
  1986. apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
  1987. apic_printk(APIC_QUIET, KERN_INFO
  1988. "...trying to set up timer as ExtINT IRQ...\n");
  1989. init_8259A(0);
  1990. make_8259A_irq(0);
  1991. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  1992. unlock_ExtINT_logic();
  1993. if (timer_irq_works()) {
  1994. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  1995. goto out;
  1996. }
  1997. apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
  1998. panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
  1999. "report. Then try booting with the 'noapic' option.\n");
  2000. out:
  2001. local_irq_restore(flags);
  2002. }
  2003. /*
  2004. * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
  2005. * to devices. However there may be an I/O APIC pin available for
  2006. * this interrupt regardless. The pin may be left unconnected, but
  2007. * typically it will be reused as an ExtINT cascade interrupt for
  2008. * the master 8259A. In the MPS case such a pin will normally be
  2009. * reported as an ExtINT interrupt in the MP table. With ACPI
  2010. * there is no provision for ExtINT interrupts, and in the absence
  2011. * of an override it would be treated as an ordinary ISA I/O APIC
  2012. * interrupt, that is edge-triggered and unmasked by default. We
  2013. * used to do this, but it caused problems on some systems because
  2014. * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
  2015. * the same ExtINT cascade interrupt to drive the local APIC of the
  2016. * bootstrap processor. Therefore we refrain from routing IRQ2 to
  2017. * the I/O APIC in all cases now. No actual device should request
  2018. * it anyway. --macro
  2019. */
  2020. #define PIC_IRQS (1 << PIC_CASCADE_IR)
  2021. void __init setup_IO_APIC(void)
  2022. {
  2023. enable_IO_APIC();
  2024. io_apic_irqs = ~PIC_IRQS;
  2025. printk("ENABLING IO-APIC IRQs\n");
  2026. /*
  2027. * Set up IO-APIC IRQ routing.
  2028. */
  2029. if (!acpi_ioapic)
  2030. setup_ioapic_ids_from_mpc();
  2031. sync_Arb_IDs();
  2032. setup_IO_APIC_irqs();
  2033. init_IO_APIC_traps();
  2034. check_timer();
  2035. }
  2036. /*
  2037. * Called after all the initialization is done. If we didnt find any
  2038. * APIC bugs then we can allow the modify fast path
  2039. */
  2040. static int __init io_apic_bug_finalize(void)
  2041. {
  2042. if (sis_apic_bug == -1)
  2043. sis_apic_bug = 0;
  2044. return 0;
  2045. }
  2046. late_initcall(io_apic_bug_finalize);
  2047. struct sysfs_ioapic_data {
  2048. struct sys_device dev;
  2049. struct IO_APIC_route_entry entry[0];
  2050. };
  2051. static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS];
  2052. static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
  2053. {
  2054. struct IO_APIC_route_entry *entry;
  2055. struct sysfs_ioapic_data *data;
  2056. int i;
  2057. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2058. entry = data->entry;
  2059. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2060. entry[i] = ioapic_read_entry(dev->id, i);
  2061. return 0;
  2062. }
  2063. static int ioapic_resume(struct sys_device *dev)
  2064. {
  2065. struct IO_APIC_route_entry *entry;
  2066. struct sysfs_ioapic_data *data;
  2067. unsigned long flags;
  2068. union IO_APIC_reg_00 reg_00;
  2069. int i;
  2070. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2071. entry = data->entry;
  2072. spin_lock_irqsave(&ioapic_lock, flags);
  2073. reg_00.raw = io_apic_read(dev->id, 0);
  2074. if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
  2075. reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
  2076. io_apic_write(dev->id, 0, reg_00.raw);
  2077. }
  2078. spin_unlock_irqrestore(&ioapic_lock, flags);
  2079. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2080. ioapic_write_entry(dev->id, i, entry[i]);
  2081. return 0;
  2082. }
  2083. static struct sysdev_class ioapic_sysdev_class = {
  2084. .name = "ioapic",
  2085. .suspend = ioapic_suspend,
  2086. .resume = ioapic_resume,
  2087. };
  2088. static int __init ioapic_init_sysfs(void)
  2089. {
  2090. struct sys_device *dev;
  2091. int i, size, error = 0;
  2092. error = sysdev_class_register(&ioapic_sysdev_class);
  2093. if (error)
  2094. return error;
  2095. for (i = 0; i < nr_ioapics; i++) {
  2096. size = sizeof(struct sys_device) + nr_ioapic_registers[i]
  2097. * sizeof(struct IO_APIC_route_entry);
  2098. mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
  2099. if (!mp_ioapic_data[i]) {
  2100. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2101. continue;
  2102. }
  2103. dev = &mp_ioapic_data[i]->dev;
  2104. dev->id = i;
  2105. dev->cls = &ioapic_sysdev_class;
  2106. error = sysdev_register(dev);
  2107. if (error) {
  2108. kfree(mp_ioapic_data[i]);
  2109. mp_ioapic_data[i] = NULL;
  2110. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2111. continue;
  2112. }
  2113. }
  2114. return 0;
  2115. }
  2116. device_initcall(ioapic_init_sysfs);
  2117. /*
  2118. * Dynamic irq allocate and deallocation
  2119. */
  2120. unsigned int create_irq_nr(unsigned int irq_want)
  2121. {
  2122. /* Allocate an unused irq */
  2123. unsigned int irq, new;
  2124. unsigned long flags;
  2125. struct irq_cfg *cfg_new;
  2126. #ifndef CONFIG_HAVE_SPARSE_IRQ
  2127. /* only can use bus/dev/fn.. when per_cpu vector is used */
  2128. irq_want = nr_irqs - 1;
  2129. #endif
  2130. irq = 0;
  2131. spin_lock_irqsave(&vector_lock, flags);
  2132. for (new = (nr_irqs - 1); new > 0; new--) {
  2133. if (platform_legacy_irq(new))
  2134. continue;
  2135. cfg_new = irq_cfg(new);
  2136. if (cfg_new && cfg_new->vector != 0)
  2137. continue;
  2138. if (!cfg_new)
  2139. cfg_new = irq_cfg_alloc(new);
  2140. if (__assign_irq_vector(new, TARGET_CPUS) == 0)
  2141. irq = new;
  2142. break;
  2143. }
  2144. spin_unlock_irqrestore(&vector_lock, flags);
  2145. if (irq > 0) {
  2146. dynamic_irq_init(irq);
  2147. }
  2148. return irq;
  2149. }
  2150. int create_irq(void)
  2151. {
  2152. return create_irq_nr(nr_irqs - 1);
  2153. }
  2154. void destroy_irq(unsigned int irq)
  2155. {
  2156. unsigned long flags;
  2157. dynamic_irq_cleanup(irq);
  2158. spin_lock_irqsave(&vector_lock, flags);
  2159. __clear_irq_vector(irq);
  2160. spin_unlock_irqrestore(&vector_lock, flags);
  2161. }
  2162. /*
  2163. * MSI message composition
  2164. */
  2165. #ifdef CONFIG_PCI_MSI
  2166. static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
  2167. {
  2168. struct irq_cfg *cfg;
  2169. int err;
  2170. unsigned dest;
  2171. cpumask_t tmp;
  2172. tmp = TARGET_CPUS;
  2173. err = assign_irq_vector(irq, tmp);
  2174. if (err)
  2175. return err;
  2176. cfg = irq_cfg(irq);
  2177. cpus_and(tmp, cfg->domain, tmp);
  2178. dest = cpu_mask_to_apicid(tmp);
  2179. msg->address_hi = MSI_ADDR_BASE_HI;
  2180. msg->address_lo =
  2181. MSI_ADDR_BASE_LO |
  2182. ((INT_DEST_MODE == 0) ?
  2183. MSI_ADDR_DEST_MODE_PHYSICAL:
  2184. MSI_ADDR_DEST_MODE_LOGICAL) |
  2185. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2186. MSI_ADDR_REDIRECTION_CPU:
  2187. MSI_ADDR_REDIRECTION_LOWPRI) |
  2188. MSI_ADDR_DEST_ID(dest);
  2189. msg->data =
  2190. MSI_DATA_TRIGGER_EDGE |
  2191. MSI_DATA_LEVEL_ASSERT |
  2192. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2193. MSI_DATA_DELIVERY_FIXED:
  2194. MSI_DATA_DELIVERY_LOWPRI) |
  2195. MSI_DATA_VECTOR(cfg->vector);
  2196. return err;
  2197. }
  2198. #ifdef CONFIG_SMP
  2199. static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask)
  2200. {
  2201. struct irq_cfg *cfg;
  2202. struct msi_msg msg;
  2203. unsigned int dest;
  2204. cpumask_t tmp;
  2205. cpus_and(tmp, mask, cpu_online_map);
  2206. if (cpus_empty(tmp))
  2207. return;
  2208. if (assign_irq_vector(irq, mask))
  2209. return;
  2210. cfg = irq_cfg(irq);
  2211. cpus_and(tmp, cfg->domain, mask);
  2212. dest = cpu_mask_to_apicid(tmp);
  2213. read_msi_msg(irq, &msg);
  2214. msg.data &= ~MSI_DATA_VECTOR_MASK;
  2215. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  2216. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  2217. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  2218. write_msi_msg(irq, &msg);
  2219. irq_to_desc(irq)->affinity = mask;
  2220. }
  2221. #endif /* CONFIG_SMP */
  2222. /*
  2223. * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
  2224. * which implement the MSI or MSI-X Capability Structure.
  2225. */
  2226. static struct irq_chip msi_chip = {
  2227. .name = "PCI-MSI",
  2228. .unmask = unmask_msi_irq,
  2229. .mask = mask_msi_irq,
  2230. .ack = ack_apic_edge,
  2231. #ifdef CONFIG_SMP
  2232. .set_affinity = set_msi_irq_affinity,
  2233. #endif
  2234. .retrigger = ioapic_retrigger_irq,
  2235. };
  2236. static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq)
  2237. {
  2238. int ret;
  2239. struct msi_msg msg;
  2240. ret = msi_compose_msg(dev, irq, &msg);
  2241. if (ret < 0)
  2242. return ret;
  2243. set_irq_msi(irq, desc);
  2244. write_msi_msg(irq, &msg);
  2245. set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
  2246. return 0;
  2247. }
  2248. static unsigned int build_irq_for_pci_dev(struct pci_dev *dev)
  2249. {
  2250. unsigned int irq;
  2251. irq = dev->bus->number;
  2252. irq <<= 8;
  2253. irq |= dev->devfn;
  2254. irq <<= 12;
  2255. return irq;
  2256. }
  2257. int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
  2258. {
  2259. int irq, ret;
  2260. unsigned int irq_want;
  2261. irq_want = build_irq_for_pci_dev(dev) + 0x100;
  2262. irq = create_irq_nr(irq_want);
  2263. if (irq == 0)
  2264. return -1;
  2265. ret = setup_msi_irq(dev, desc, irq);
  2266. if (ret < 0) {
  2267. destroy_irq(irq);
  2268. return ret;
  2269. }
  2270. return 0;
  2271. }
  2272. void arch_teardown_msi_irq(unsigned int irq)
  2273. {
  2274. destroy_irq(irq);
  2275. }
  2276. #endif /* CONFIG_PCI_MSI */
  2277. /*
  2278. * Hypertransport interrupt support
  2279. */
  2280. #ifdef CONFIG_HT_IRQ
  2281. #ifdef CONFIG_SMP
  2282. static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
  2283. {
  2284. struct ht_irq_msg msg;
  2285. fetch_ht_irq_msg(irq, &msg);
  2286. msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
  2287. msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
  2288. msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
  2289. msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
  2290. write_ht_irq_msg(irq, &msg);
  2291. }
  2292. static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask)
  2293. {
  2294. struct irq_cfg *cfg;
  2295. unsigned int dest;
  2296. cpumask_t tmp;
  2297. cpus_and(tmp, mask, cpu_online_map);
  2298. if (cpus_empty(tmp))
  2299. return;
  2300. if (assign_irq_vector(irq, mask))
  2301. return;
  2302. cfg = irq_cfg(irq);
  2303. cpus_and(tmp, cfg->domain, mask);
  2304. dest = cpu_mask_to_apicid(tmp);
  2305. target_ht_irq(irq, dest, cfg->vector);
  2306. irq_to_desc(irq)->affinity = mask;
  2307. }
  2308. #endif
  2309. static struct irq_chip ht_irq_chip = {
  2310. .name = "PCI-HT",
  2311. .mask = mask_ht_irq,
  2312. .unmask = unmask_ht_irq,
  2313. .ack = ack_apic_edge,
  2314. #ifdef CONFIG_SMP
  2315. .set_affinity = set_ht_irq_affinity,
  2316. #endif
  2317. .retrigger = ioapic_retrigger_irq,
  2318. };
  2319. int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
  2320. {
  2321. struct irq_cfg *cfg;
  2322. int err;
  2323. cpumask_t tmp;
  2324. tmp = TARGET_CPUS;
  2325. err = assign_irq_vector(irq, tmp);
  2326. if ( !err) {
  2327. struct ht_irq_msg msg;
  2328. unsigned dest;
  2329. cfg = irq_cfg(irq);
  2330. cpus_and(tmp, cfg->domain, tmp);
  2331. dest = cpu_mask_to_apicid(tmp);
  2332. msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
  2333. msg.address_lo =
  2334. HT_IRQ_LOW_BASE |
  2335. HT_IRQ_LOW_DEST_ID(dest) |
  2336. HT_IRQ_LOW_VECTOR(cfg->vector) |
  2337. ((INT_DEST_MODE == 0) ?
  2338. HT_IRQ_LOW_DM_PHYSICAL :
  2339. HT_IRQ_LOW_DM_LOGICAL) |
  2340. HT_IRQ_LOW_RQEOI_EDGE |
  2341. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2342. HT_IRQ_LOW_MT_FIXED :
  2343. HT_IRQ_LOW_MT_ARBITRATED) |
  2344. HT_IRQ_LOW_IRQ_MASKED;
  2345. write_ht_irq_msg(irq, &msg);
  2346. set_irq_chip_and_handler_name(irq, &ht_irq_chip,
  2347. handle_edge_irq, "edge");
  2348. }
  2349. return err;
  2350. }
  2351. #endif /* CONFIG_HT_IRQ */
  2352. /* --------------------------------------------------------------------------
  2353. ACPI-based IOAPIC Configuration
  2354. -------------------------------------------------------------------------- */
  2355. #ifdef CONFIG_ACPI
  2356. int __init io_apic_get_unique_id(int ioapic, int apic_id)
  2357. {
  2358. union IO_APIC_reg_00 reg_00;
  2359. static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
  2360. physid_mask_t tmp;
  2361. unsigned long flags;
  2362. int i = 0;
  2363. /*
  2364. * The P4 platform supports up to 256 APIC IDs on two separate APIC
  2365. * buses (one for LAPICs, one for IOAPICs), where predecessors only
  2366. * supports up to 16 on one shared APIC bus.
  2367. *
  2368. * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
  2369. * advantage of new APIC bus architecture.
  2370. */
  2371. if (physids_empty(apic_id_map))
  2372. apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);
  2373. spin_lock_irqsave(&ioapic_lock, flags);
  2374. reg_00.raw = io_apic_read(ioapic, 0);
  2375. spin_unlock_irqrestore(&ioapic_lock, flags);
  2376. if (apic_id >= get_physical_broadcast()) {
  2377. printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
  2378. "%d\n", ioapic, apic_id, reg_00.bits.ID);
  2379. apic_id = reg_00.bits.ID;
  2380. }
  2381. /*
  2382. * Every APIC in a system must have a unique ID or we get lots of nice
  2383. * 'stuck on smp_invalidate_needed IPI wait' messages.
  2384. */
  2385. if (check_apicid_used(apic_id_map, apic_id)) {
  2386. for (i = 0; i < get_physical_broadcast(); i++) {
  2387. if (!check_apicid_used(apic_id_map, i))
  2388. break;
  2389. }
  2390. if (i == get_physical_broadcast())
  2391. panic("Max apic_id exceeded!\n");
  2392. printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
  2393. "trying %d\n", ioapic, apic_id, i);
  2394. apic_id = i;
  2395. }
  2396. tmp = apicid_to_cpu_present(apic_id);
  2397. physids_or(apic_id_map, apic_id_map, tmp);
  2398. if (reg_00.bits.ID != apic_id) {
  2399. reg_00.bits.ID = apic_id;
  2400. spin_lock_irqsave(&ioapic_lock, flags);
  2401. io_apic_write(ioapic, 0, reg_00.raw);
  2402. reg_00.raw = io_apic_read(ioapic, 0);
  2403. spin_unlock_irqrestore(&ioapic_lock, flags);
  2404. /* Sanity check */
  2405. if (reg_00.bits.ID != apic_id) {
  2406. printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
  2407. return -1;
  2408. }
  2409. }
  2410. apic_printk(APIC_VERBOSE, KERN_INFO
  2411. "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
  2412. return apic_id;
  2413. }
  2414. int __init io_apic_get_version(int ioapic)
  2415. {
  2416. union IO_APIC_reg_01 reg_01;
  2417. unsigned long flags;
  2418. spin_lock_irqsave(&ioapic_lock, flags);
  2419. reg_01.raw = io_apic_read(ioapic, 1);
  2420. spin_unlock_irqrestore(&ioapic_lock, flags);
  2421. return reg_01.bits.version;
  2422. }
  2423. int __init io_apic_get_redir_entries(int ioapic)
  2424. {
  2425. union IO_APIC_reg_01 reg_01;
  2426. unsigned long flags;
  2427. spin_lock_irqsave(&ioapic_lock, flags);
  2428. reg_01.raw = io_apic_read(ioapic, 1);
  2429. spin_unlock_irqrestore(&ioapic_lock, flags);
  2430. return reg_01.bits.entries;
  2431. }
  2432. int io_apic_set_pci_routing(int ioapic, int pin, int irq, int triggering, int polarity)
  2433. {
  2434. if (!IO_APIC_IRQ(irq)) {
  2435. printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
  2436. ioapic);
  2437. return -EINVAL;
  2438. }
  2439. /*
  2440. * IRQs < 16 are already in the irq_2_pin[] map
  2441. */
  2442. if (irq >= 16)
  2443. add_pin_to_irq(irq, ioapic, pin);
  2444. setup_IO_APIC_irq(ioapic, pin, irq, triggering, polarity);
  2445. return 0;
  2446. }
  2447. int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
  2448. {
  2449. int i;
  2450. if (skip_ioapic_setup)
  2451. return -1;
  2452. for (i = 0; i < mp_irq_entries; i++)
  2453. if (mp_irqs[i].mp_irqtype == mp_INT &&
  2454. mp_irqs[i].mp_srcbusirq == bus_irq)
  2455. break;
  2456. if (i >= mp_irq_entries)
  2457. return -1;
  2458. *trigger = irq_trigger(i);
  2459. *polarity = irq_polarity(i);
  2460. return 0;
  2461. }
  2462. #endif /* CONFIG_ACPI */
  2463. /*
  2464. * This function currently is only a helper for the i386 smp boot process where
  2465. * we need to reprogram the ioredtbls to cater for the cpus which have come online
  2466. * so mask in all cases should simply be TARGET_CPUS
  2467. */
  2468. #ifdef CONFIG_SMP
  2469. void __init setup_ioapic_dest(void)
  2470. {
  2471. int pin, ioapic, irq, irq_entry;
  2472. struct irq_cfg *cfg;
  2473. struct irq_desc *desc;
  2474. if (skip_ioapic_setup == 1)
  2475. return;
  2476. for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
  2477. for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
  2478. irq_entry = find_irq_entry(ioapic, pin, mp_INT);
  2479. if (irq_entry == -1)
  2480. continue;
  2481. irq = pin_2_irq(irq_entry, ioapic, pin);
  2482. /* setup_IO_APIC_irqs could fail to get vector for some device
  2483. * when you have too many devices, because at that time only boot
  2484. * cpu is online.
  2485. */
  2486. cfg = irq_cfg(irq);
  2487. if (!cfg->vector)
  2488. setup_IO_APIC_irq(ioapic, pin, irq,
  2489. irq_trigger(irq_entry),
  2490. irq_polarity(irq_entry));
  2491. else {
  2492. desc = irq_to_desc(irq);
  2493. set_ioapic_affinity_irq(irq, TARGET_CPUS);
  2494. }
  2495. }
  2496. }
  2497. }
  2498. #endif
  2499. static int __init parse_disable_timer_pin_1(char *arg)
  2500. {
  2501. disable_timer_pin_1 = 1;
  2502. return 0;
  2503. }
  2504. early_param("disable_timer_pin_1", parse_disable_timer_pin_1);
  2505. static int __init parse_enable_timer_pin_1(char *arg)
  2506. {
  2507. disable_timer_pin_1 = -1;
  2508. return 0;
  2509. }
  2510. early_param("enable_timer_pin_1", parse_enable_timer_pin_1);
  2511. static int __init parse_noapic(char *arg)
  2512. {
  2513. /* disable IO-APIC */
  2514. disable_ioapic_setup();
  2515. return 0;
  2516. }
  2517. early_param("noapic", parse_noapic);
  2518. void __init ioapic_init_mappings(void)
  2519. {
  2520. unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
  2521. int i;
  2522. for (i = 0; i < nr_ioapics; i++) {
  2523. if (smp_found_config) {
  2524. ioapic_phys = mp_ioapics[i].mp_apicaddr;
  2525. if (!ioapic_phys) {
  2526. printk(KERN_ERR
  2527. "WARNING: bogus zero IO-APIC "
  2528. "address found in MPTABLE, "
  2529. "disabling IO/APIC support!\n");
  2530. smp_found_config = 0;
  2531. skip_ioapic_setup = 1;
  2532. goto fake_ioapic_page;
  2533. }
  2534. } else {
  2535. fake_ioapic_page:
  2536. ioapic_phys = (unsigned long)
  2537. alloc_bootmem_pages(PAGE_SIZE);
  2538. ioapic_phys = __pa(ioapic_phys);
  2539. }
  2540. set_fixmap_nocache(idx, ioapic_phys);
  2541. printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
  2542. __fix_to_virt(idx), ioapic_phys);
  2543. idx++;
  2544. }
  2545. }