io_apic_32.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027
  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. static inline int IO_APIC_irq_trigger(int irq)
  874. {
  875. int apic, idx, pin;
  876. for (apic = 0; apic < nr_ioapics; apic++) {
  877. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  878. idx = find_irq_entry(apic, pin, mp_INT);
  879. if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
  880. return irq_trigger(idx);
  881. }
  882. }
  883. /*
  884. * nonexistent IRQs are edge default
  885. */
  886. return 0;
  887. }
  888. void lock_vector_lock(void)
  889. {
  890. /* Used to the online set of cpus does not change
  891. * during assign_irq_vector.
  892. */
  893. spin_lock(&vector_lock);
  894. }
  895. void unlock_vector_lock(void)
  896. {
  897. spin_unlock(&vector_lock);
  898. }
  899. static int __assign_irq_vector(int irq, cpumask_t mask)
  900. {
  901. static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
  902. unsigned int old_vector;
  903. int cpu;
  904. struct irq_cfg *cfg;
  905. cfg = irq_cfg(irq);
  906. /* Only try and allocate irqs on cpus that are present */
  907. cpus_and(mask, mask, cpu_online_map);
  908. if ((cfg->move_in_progress) || cfg->move_cleanup_count)
  909. return -EBUSY;
  910. old_vector = cfg->vector;
  911. if (old_vector) {
  912. cpumask_t tmp;
  913. cpus_and(tmp, cfg->domain, mask);
  914. if (!cpus_empty(tmp))
  915. return 0;
  916. }
  917. for_each_cpu_mask_nr(cpu, mask) {
  918. cpumask_t domain, new_mask;
  919. int new_cpu;
  920. int vector, offset;
  921. domain = vector_allocation_domain(cpu);
  922. cpus_and(new_mask, domain, cpu_online_map);
  923. vector = current_vector;
  924. offset = current_offset;
  925. next:
  926. vector += 8;
  927. if (vector >= first_system_vector) {
  928. /* If we run out of vectors on large boxen, must share them. */
  929. offset = (offset + 1) % 8;
  930. vector = FIRST_DEVICE_VECTOR + offset;
  931. }
  932. if (unlikely(current_vector == vector))
  933. continue;
  934. if (vector == SYSCALL_VECTOR)
  935. goto next;
  936. for_each_cpu_mask_nr(new_cpu, new_mask)
  937. if (per_cpu(vector_irq, new_cpu)[vector] != -1)
  938. goto next;
  939. /* Found one! */
  940. current_vector = vector;
  941. current_offset = offset;
  942. if (old_vector) {
  943. cfg->move_in_progress = 1;
  944. cfg->old_domain = cfg->domain;
  945. }
  946. printk(KERN_DEBUG "assign_irq_vector: irq %d vector %#x cpu ", irq, vector);
  947. for_each_cpu_mask_nr(new_cpu, new_mask) {
  948. per_cpu(vector_irq, new_cpu)[vector] = irq;
  949. printk(KERN_CONT " %d ", new_cpu);
  950. }
  951. printk(KERN_CONT "\n");
  952. cfg->vector = vector;
  953. cfg->domain = domain;
  954. return 0;
  955. }
  956. return -ENOSPC;
  957. }
  958. static int assign_irq_vector(int irq, cpumask_t mask)
  959. {
  960. int err;
  961. unsigned long flags;
  962. spin_lock_irqsave(&vector_lock, flags);
  963. err = __assign_irq_vector(irq, mask);
  964. spin_unlock_irqrestore(&vector_lock, flags);
  965. return err;
  966. }
  967. static void __clear_irq_vector(int irq)
  968. {
  969. struct irq_cfg *cfg;
  970. cpumask_t mask;
  971. int cpu, vector;
  972. cfg = irq_cfg(irq);
  973. BUG_ON(!cfg->vector);
  974. vector = cfg->vector;
  975. cpus_and(mask, cfg->domain, cpu_online_map);
  976. for_each_cpu_mask_nr(cpu, mask)
  977. per_cpu(vector_irq, cpu)[vector] = -1;
  978. cfg->vector = 0;
  979. cpus_clear(cfg->domain);
  980. }
  981. void __setup_vector_irq(int cpu)
  982. {
  983. /* Initialize vector_irq on a new cpu */
  984. /* This function must be called with vector_lock held */
  985. int irq, vector;
  986. struct irq_cfg *cfg;
  987. /* Mark the inuse vectors */
  988. for_each_irq_cfg(cfg) {
  989. if (!cpu_isset(cpu, cfg->domain))
  990. continue;
  991. vector = cfg->vector;
  992. irq = cfg->irq;
  993. per_cpu(vector_irq, cpu)[vector] = irq;
  994. }
  995. /* Mark the free vectors */
  996. for (vector = 0; vector < NR_VECTORS; ++vector) {
  997. irq = per_cpu(vector_irq, cpu)[vector];
  998. if (irq < 0)
  999. continue;
  1000. cfg = irq_cfg(irq);
  1001. if (!cpu_isset(cpu, cfg->domain))
  1002. per_cpu(vector_irq, cpu)[vector] = -1;
  1003. }
  1004. }
  1005. static struct irq_chip ioapic_chip;
  1006. #define IOAPIC_AUTO -1
  1007. #define IOAPIC_EDGE 0
  1008. #define IOAPIC_LEVEL 1
  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 void irq_complete_move(unsigned int irq);
  1628. static void ack_ioapic_irq(unsigned int irq)
  1629. {
  1630. irq_complete_move(irq);
  1631. move_native_irq(irq);
  1632. ack_APIC_irq();
  1633. }
  1634. static void ack_ioapic_quirk_irq(unsigned int irq)
  1635. {
  1636. unsigned long v;
  1637. int i;
  1638. irq_complete_move(irq);
  1639. move_native_irq(irq);
  1640. /*
  1641. * It appears there is an erratum which affects at least version 0x11
  1642. * of I/O APIC (that's the 82093AA and cores integrated into various
  1643. * chipsets). Under certain conditions a level-triggered interrupt is
  1644. * erroneously delivered as edge-triggered one but the respective IRR
  1645. * bit gets set nevertheless. As a result the I/O unit expects an EOI
  1646. * message but it will never arrive and further interrupts are blocked
  1647. * from the source. The exact reason is so far unknown, but the
  1648. * phenomenon was observed when two consecutive interrupt requests
  1649. * from a given source get delivered to the same CPU and the source is
  1650. * temporarily disabled in between.
  1651. *
  1652. * A workaround is to simulate an EOI message manually. We achieve it
  1653. * by setting the trigger mode to edge and then to level when the edge
  1654. * trigger mode gets detected in the TMR of a local APIC for a
  1655. * level-triggered interrupt. We mask the source for the time of the
  1656. * operation to prevent an edge-triggered interrupt escaping meanwhile.
  1657. * The idea is from Manfred Spraul. --macro
  1658. */
  1659. i = irq_cfg(irq)->vector;
  1660. v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
  1661. ack_APIC_irq();
  1662. if (!(v & (1 << (i & 0x1f)))) {
  1663. atomic_inc(&irq_mis_count);
  1664. spin_lock(&ioapic_lock);
  1665. __mask_and_edge_IO_APIC_irq(irq);
  1666. __unmask_and_level_IO_APIC_irq(irq);
  1667. spin_unlock(&ioapic_lock);
  1668. }
  1669. }
  1670. static int ioapic_retrigger_irq(unsigned int irq)
  1671. {
  1672. send_IPI_self(irq_cfg(irq)->vector);
  1673. return 1;
  1674. }
  1675. #ifdef CONFIG_SMP
  1676. asmlinkage void smp_irq_move_cleanup_interrupt(void)
  1677. {
  1678. unsigned vector, me;
  1679. ack_APIC_irq();
  1680. irq_enter();
  1681. me = smp_processor_id();
  1682. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  1683. unsigned int irq;
  1684. struct irq_desc *desc;
  1685. struct irq_cfg *cfg;
  1686. irq = __get_cpu_var(vector_irq)[vector];
  1687. desc = irq_to_desc(irq);
  1688. if (!desc)
  1689. continue;
  1690. cfg = irq_cfg(irq);
  1691. spin_lock(&desc->lock);
  1692. if (!cfg->move_cleanup_count)
  1693. goto unlock;
  1694. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain))
  1695. goto unlock;
  1696. __get_cpu_var(vector_irq)[vector] = -1;
  1697. cfg->move_cleanup_count--;
  1698. unlock:
  1699. spin_unlock(&desc->lock);
  1700. }
  1701. irq_exit();
  1702. }
  1703. static void irq_complete_move(unsigned int irq)
  1704. {
  1705. struct irq_cfg *cfg = irq_cfg(irq);
  1706. unsigned vector, me;
  1707. if (likely(!cfg->move_in_progress))
  1708. return;
  1709. vector = ~get_irq_regs()->orig_ax;
  1710. me = smp_processor_id();
  1711. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) {
  1712. cpumask_t cleanup_mask;
  1713. cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map);
  1714. cfg->move_cleanup_count = cpus_weight(cleanup_mask);
  1715. send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  1716. cfg->move_in_progress = 0;
  1717. }
  1718. }
  1719. #else
  1720. static inline void irq_complete_move(unsigned int irq) {}
  1721. #endif
  1722. static struct irq_chip ioapic_chip __read_mostly = {
  1723. .name = "IO-APIC",
  1724. .startup = startup_ioapic_irq,
  1725. .mask = mask_IO_APIC_irq,
  1726. .unmask = unmask_IO_APIC_irq,
  1727. .ack = ack_ioapic_irq,
  1728. .eoi = ack_ioapic_quirk_irq,
  1729. #ifdef CONFIG_SMP
  1730. .set_affinity = set_ioapic_affinity_irq,
  1731. #endif
  1732. .retrigger = ioapic_retrigger_irq,
  1733. };
  1734. static inline void init_IO_APIC_traps(void)
  1735. {
  1736. int irq;
  1737. struct irq_desc *desc;
  1738. struct irq_cfg *cfg;
  1739. /*
  1740. * NOTE! The local APIC isn't very good at handling
  1741. * multiple interrupts at the same interrupt level.
  1742. * As the interrupt level is determined by taking the
  1743. * vector number and shifting that right by 4, we
  1744. * want to spread these out a bit so that they don't
  1745. * all fall in the same interrupt level.
  1746. *
  1747. * Also, we've got to be careful not to trash gate
  1748. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  1749. */
  1750. for_each_irq_cfg(cfg) {
  1751. irq = cfg->irq;
  1752. if (IO_APIC_IRQ(irq) && !cfg->vector) {
  1753. /*
  1754. * Hmm.. We don't have an entry for this,
  1755. * so default to an old-fashioned 8259
  1756. * interrupt if we can..
  1757. */
  1758. if (irq < 16)
  1759. make_8259A_irq(irq);
  1760. else {
  1761. desc = irq_to_desc(irq);
  1762. /* Strange. Oh, well.. */
  1763. desc->chip = &no_irq_chip;
  1764. }
  1765. }
  1766. }
  1767. }
  1768. /*
  1769. * The local APIC irq-chip implementation:
  1770. */
  1771. static void ack_lapic_irq(unsigned int irq)
  1772. {
  1773. ack_APIC_irq();
  1774. }
  1775. static void mask_lapic_irq(unsigned int irq)
  1776. {
  1777. unsigned long v;
  1778. v = apic_read(APIC_LVT0);
  1779. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  1780. }
  1781. static void unmask_lapic_irq(unsigned int irq)
  1782. {
  1783. unsigned long v;
  1784. v = apic_read(APIC_LVT0);
  1785. apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
  1786. }
  1787. static struct irq_chip lapic_chip __read_mostly = {
  1788. .name = "local-APIC",
  1789. .mask = mask_lapic_irq,
  1790. .unmask = unmask_lapic_irq,
  1791. .ack = ack_lapic_irq,
  1792. };
  1793. static void lapic_register_intr(int irq)
  1794. {
  1795. struct irq_desc *desc;
  1796. desc = irq_to_desc(irq);
  1797. desc->status &= ~IRQ_LEVEL;
  1798. set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
  1799. "edge");
  1800. }
  1801. static void __init setup_nmi(void)
  1802. {
  1803. /*
  1804. * Dirty trick to enable the NMI watchdog ...
  1805. * We put the 8259A master into AEOI mode and
  1806. * unmask on all local APICs LVT0 as NMI.
  1807. *
  1808. * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
  1809. * is from Maciej W. Rozycki - so we do not have to EOI from
  1810. * the NMI handler or the timer interrupt.
  1811. */
  1812. apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
  1813. enable_NMI_through_LVT0();
  1814. apic_printk(APIC_VERBOSE, " done.\n");
  1815. }
  1816. /*
  1817. * This looks a bit hackish but it's about the only one way of sending
  1818. * a few INTA cycles to 8259As and any associated glue logic. ICR does
  1819. * not support the ExtINT mode, unfortunately. We need to send these
  1820. * cycles as some i82489DX-based boards have glue logic that keeps the
  1821. * 8259A interrupt line asserted until INTA. --macro
  1822. */
  1823. static inline void __init unlock_ExtINT_logic(void)
  1824. {
  1825. int apic, pin, i;
  1826. struct IO_APIC_route_entry entry0, entry1;
  1827. unsigned char save_control, save_freq_select;
  1828. pin = find_isa_irq_pin(8, mp_INT);
  1829. if (pin == -1) {
  1830. WARN_ON_ONCE(1);
  1831. return;
  1832. }
  1833. apic = find_isa_irq_apic(8, mp_INT);
  1834. if (apic == -1) {
  1835. WARN_ON_ONCE(1);
  1836. return;
  1837. }
  1838. entry0 = ioapic_read_entry(apic, pin);
  1839. clear_IO_APIC_pin(apic, pin);
  1840. memset(&entry1, 0, sizeof(entry1));
  1841. entry1.dest_mode = 0; /* physical delivery */
  1842. entry1.mask = 0; /* unmask IRQ now */
  1843. entry1.dest = hard_smp_processor_id();
  1844. entry1.delivery_mode = dest_ExtINT;
  1845. entry1.polarity = entry0.polarity;
  1846. entry1.trigger = 0;
  1847. entry1.vector = 0;
  1848. ioapic_write_entry(apic, pin, entry1);
  1849. save_control = CMOS_READ(RTC_CONTROL);
  1850. save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
  1851. CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
  1852. RTC_FREQ_SELECT);
  1853. CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
  1854. i = 100;
  1855. while (i-- > 0) {
  1856. mdelay(10);
  1857. if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
  1858. i -= 10;
  1859. }
  1860. CMOS_WRITE(save_control, RTC_CONTROL);
  1861. CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
  1862. clear_IO_APIC_pin(apic, pin);
  1863. ioapic_write_entry(apic, pin, entry0);
  1864. }
  1865. /*
  1866. * This code may look a bit paranoid, but it's supposed to cooperate with
  1867. * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
  1868. * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
  1869. * fanatically on his truly buggy board.
  1870. */
  1871. static inline void __init check_timer(void)
  1872. {
  1873. struct irq_cfg *cfg = irq_cfg(0);
  1874. int apic1, pin1, apic2, pin2;
  1875. int no_pin1 = 0;
  1876. unsigned int ver;
  1877. unsigned long flags;
  1878. local_irq_save(flags);
  1879. ver = apic_read(APIC_LVR);
  1880. ver = GET_APIC_VERSION(ver);
  1881. /*
  1882. * get/set the timer IRQ vector:
  1883. */
  1884. disable_8259A_irq(0);
  1885. assign_irq_vector(0, TARGET_CPUS);
  1886. /*
  1887. * As IRQ0 is to be enabled in the 8259A, the virtual
  1888. * wire has to be disabled in the local APIC. Also
  1889. * timer interrupts need to be acknowledged manually in
  1890. * the 8259A for the i82489DX when using the NMI
  1891. * watchdog as that APIC treats NMIs as level-triggered.
  1892. * The AEOI mode will finish them in the 8259A
  1893. * automatically.
  1894. */
  1895. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  1896. init_8259A(1);
  1897. timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
  1898. pin1 = find_isa_irq_pin(0, mp_INT);
  1899. apic1 = find_isa_irq_apic(0, mp_INT);
  1900. pin2 = ioapic_i8259.pin;
  1901. apic2 = ioapic_i8259.apic;
  1902. apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
  1903. "apic1=%d pin1=%d apic2=%d pin2=%d\n",
  1904. cfg->vector, apic1, pin1, apic2, pin2);
  1905. /*
  1906. * Some BIOS writers are clueless and report the ExtINTA
  1907. * I/O APIC input from the cascaded 8259A as the timer
  1908. * interrupt input. So just in case, if only one pin
  1909. * was found above, try it both directly and through the
  1910. * 8259A.
  1911. */
  1912. if (pin1 == -1) {
  1913. pin1 = pin2;
  1914. apic1 = apic2;
  1915. no_pin1 = 1;
  1916. } else if (pin2 == -1) {
  1917. pin2 = pin1;
  1918. apic2 = apic1;
  1919. }
  1920. if (pin1 != -1) {
  1921. /*
  1922. * Ok, does IRQ0 through the IOAPIC work?
  1923. */
  1924. if (no_pin1) {
  1925. add_pin_to_irq(0, apic1, pin1);
  1926. setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
  1927. }
  1928. unmask_IO_APIC_irq(0);
  1929. if (timer_irq_works()) {
  1930. if (nmi_watchdog == NMI_IO_APIC) {
  1931. setup_nmi();
  1932. enable_8259A_irq(0);
  1933. }
  1934. if (disable_timer_pin_1 > 0)
  1935. clear_IO_APIC_pin(0, pin1);
  1936. goto out;
  1937. }
  1938. clear_IO_APIC_pin(apic1, pin1);
  1939. if (!no_pin1)
  1940. apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
  1941. "8254 timer not connected to IO-APIC\n");
  1942. apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
  1943. "(IRQ0) through the 8259A ...\n");
  1944. apic_printk(APIC_QUIET, KERN_INFO
  1945. "..... (found apic %d pin %d) ...\n", apic2, pin2);
  1946. /*
  1947. * legacy devices should be connected to IO APIC #0
  1948. */
  1949. replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
  1950. setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
  1951. unmask_IO_APIC_irq(0);
  1952. enable_8259A_irq(0);
  1953. if (timer_irq_works()) {
  1954. apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
  1955. timer_through_8259 = 1;
  1956. if (nmi_watchdog == NMI_IO_APIC) {
  1957. disable_8259A_irq(0);
  1958. setup_nmi();
  1959. enable_8259A_irq(0);
  1960. }
  1961. goto out;
  1962. }
  1963. /*
  1964. * Cleanup, just in case ...
  1965. */
  1966. disable_8259A_irq(0);
  1967. clear_IO_APIC_pin(apic2, pin2);
  1968. apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
  1969. }
  1970. if (nmi_watchdog == NMI_IO_APIC) {
  1971. apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
  1972. "through the IO-APIC - disabling NMI Watchdog!\n");
  1973. nmi_watchdog = NMI_NONE;
  1974. }
  1975. timer_ack = 0;
  1976. apic_printk(APIC_QUIET, KERN_INFO
  1977. "...trying to set up timer as Virtual Wire IRQ...\n");
  1978. lapic_register_intr(0);
  1979. apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
  1980. enable_8259A_irq(0);
  1981. if (timer_irq_works()) {
  1982. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  1983. goto out;
  1984. }
  1985. disable_8259A_irq(0);
  1986. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
  1987. apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
  1988. apic_printk(APIC_QUIET, KERN_INFO
  1989. "...trying to set up timer as ExtINT IRQ...\n");
  1990. init_8259A(0);
  1991. make_8259A_irq(0);
  1992. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  1993. unlock_ExtINT_logic();
  1994. if (timer_irq_works()) {
  1995. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  1996. goto out;
  1997. }
  1998. apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
  1999. panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
  2000. "report. Then try booting with the 'noapic' option.\n");
  2001. out:
  2002. local_irq_restore(flags);
  2003. }
  2004. /*
  2005. * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
  2006. * to devices. However there may be an I/O APIC pin available for
  2007. * this interrupt regardless. The pin may be left unconnected, but
  2008. * typically it will be reused as an ExtINT cascade interrupt for
  2009. * the master 8259A. In the MPS case such a pin will normally be
  2010. * reported as an ExtINT interrupt in the MP table. With ACPI
  2011. * there is no provision for ExtINT interrupts, and in the absence
  2012. * of an override it would be treated as an ordinary ISA I/O APIC
  2013. * interrupt, that is edge-triggered and unmasked by default. We
  2014. * used to do this, but it caused problems on some systems because
  2015. * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
  2016. * the same ExtINT cascade interrupt to drive the local APIC of the
  2017. * bootstrap processor. Therefore we refrain from routing IRQ2 to
  2018. * the I/O APIC in all cases now. No actual device should request
  2019. * it anyway. --macro
  2020. */
  2021. #define PIC_IRQS (1 << PIC_CASCADE_IR)
  2022. void __init setup_IO_APIC(void)
  2023. {
  2024. enable_IO_APIC();
  2025. io_apic_irqs = ~PIC_IRQS;
  2026. printk("ENABLING IO-APIC IRQs\n");
  2027. /*
  2028. * Set up IO-APIC IRQ routing.
  2029. */
  2030. if (!acpi_ioapic)
  2031. setup_ioapic_ids_from_mpc();
  2032. sync_Arb_IDs();
  2033. setup_IO_APIC_irqs();
  2034. init_IO_APIC_traps();
  2035. check_timer();
  2036. }
  2037. /*
  2038. * Called after all the initialization is done. If we didnt find any
  2039. * APIC bugs then we can allow the modify fast path
  2040. */
  2041. static int __init io_apic_bug_finalize(void)
  2042. {
  2043. if (sis_apic_bug == -1)
  2044. sis_apic_bug = 0;
  2045. return 0;
  2046. }
  2047. late_initcall(io_apic_bug_finalize);
  2048. struct sysfs_ioapic_data {
  2049. struct sys_device dev;
  2050. struct IO_APIC_route_entry entry[0];
  2051. };
  2052. static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS];
  2053. static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
  2054. {
  2055. struct IO_APIC_route_entry *entry;
  2056. struct sysfs_ioapic_data *data;
  2057. int i;
  2058. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2059. entry = data->entry;
  2060. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2061. entry[i] = ioapic_read_entry(dev->id, i);
  2062. return 0;
  2063. }
  2064. static int ioapic_resume(struct sys_device *dev)
  2065. {
  2066. struct IO_APIC_route_entry *entry;
  2067. struct sysfs_ioapic_data *data;
  2068. unsigned long flags;
  2069. union IO_APIC_reg_00 reg_00;
  2070. int i;
  2071. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2072. entry = data->entry;
  2073. spin_lock_irqsave(&ioapic_lock, flags);
  2074. reg_00.raw = io_apic_read(dev->id, 0);
  2075. if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
  2076. reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
  2077. io_apic_write(dev->id, 0, reg_00.raw);
  2078. }
  2079. spin_unlock_irqrestore(&ioapic_lock, flags);
  2080. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2081. ioapic_write_entry(dev->id, i, entry[i]);
  2082. return 0;
  2083. }
  2084. static struct sysdev_class ioapic_sysdev_class = {
  2085. .name = "ioapic",
  2086. .suspend = ioapic_suspend,
  2087. .resume = ioapic_resume,
  2088. };
  2089. static int __init ioapic_init_sysfs(void)
  2090. {
  2091. struct sys_device *dev;
  2092. int i, size, error = 0;
  2093. error = sysdev_class_register(&ioapic_sysdev_class);
  2094. if (error)
  2095. return error;
  2096. for (i = 0; i < nr_ioapics; i++) {
  2097. size = sizeof(struct sys_device) + nr_ioapic_registers[i]
  2098. * sizeof(struct IO_APIC_route_entry);
  2099. mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
  2100. if (!mp_ioapic_data[i]) {
  2101. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2102. continue;
  2103. }
  2104. dev = &mp_ioapic_data[i]->dev;
  2105. dev->id = i;
  2106. dev->cls = &ioapic_sysdev_class;
  2107. error = sysdev_register(dev);
  2108. if (error) {
  2109. kfree(mp_ioapic_data[i]);
  2110. mp_ioapic_data[i] = NULL;
  2111. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2112. continue;
  2113. }
  2114. }
  2115. return 0;
  2116. }
  2117. device_initcall(ioapic_init_sysfs);
  2118. /*
  2119. * Dynamic irq allocate and deallocation
  2120. */
  2121. unsigned int create_irq_nr(unsigned int irq_want)
  2122. {
  2123. /* Allocate an unused irq */
  2124. unsigned int irq, new;
  2125. unsigned long flags;
  2126. struct irq_cfg *cfg_new;
  2127. #ifndef CONFIG_HAVE_SPARSE_IRQ
  2128. /* only can use bus/dev/fn.. when per_cpu vector is used */
  2129. irq_want = nr_irqs - 1;
  2130. #endif
  2131. irq = 0;
  2132. spin_lock_irqsave(&vector_lock, flags);
  2133. for (new = (nr_irqs - 1); new > 0; new--) {
  2134. if (platform_legacy_irq(new))
  2135. continue;
  2136. cfg_new = irq_cfg(new);
  2137. if (cfg_new && cfg_new->vector != 0)
  2138. continue;
  2139. if (!cfg_new)
  2140. cfg_new = irq_cfg_alloc(new);
  2141. if (__assign_irq_vector(new, TARGET_CPUS) == 0)
  2142. irq = new;
  2143. break;
  2144. }
  2145. spin_unlock_irqrestore(&vector_lock, flags);
  2146. if (irq > 0) {
  2147. dynamic_irq_init(irq);
  2148. }
  2149. return irq;
  2150. }
  2151. int create_irq(void)
  2152. {
  2153. return create_irq_nr(nr_irqs - 1);
  2154. }
  2155. void destroy_irq(unsigned int irq)
  2156. {
  2157. unsigned long flags;
  2158. dynamic_irq_cleanup(irq);
  2159. spin_lock_irqsave(&vector_lock, flags);
  2160. __clear_irq_vector(irq);
  2161. spin_unlock_irqrestore(&vector_lock, flags);
  2162. }
  2163. /*
  2164. * MSI message composition
  2165. */
  2166. #ifdef CONFIG_PCI_MSI
  2167. static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
  2168. {
  2169. struct irq_cfg *cfg;
  2170. int err;
  2171. unsigned dest;
  2172. cpumask_t tmp;
  2173. tmp = TARGET_CPUS;
  2174. err = assign_irq_vector(irq, tmp);
  2175. if (err)
  2176. return err;
  2177. cfg = irq_cfg(irq);
  2178. cpus_and(tmp, cfg->domain, tmp);
  2179. dest = cpu_mask_to_apicid(tmp);
  2180. msg->address_hi = MSI_ADDR_BASE_HI;
  2181. msg->address_lo =
  2182. MSI_ADDR_BASE_LO |
  2183. ((INT_DEST_MODE == 0) ?
  2184. MSI_ADDR_DEST_MODE_PHYSICAL:
  2185. MSI_ADDR_DEST_MODE_LOGICAL) |
  2186. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2187. MSI_ADDR_REDIRECTION_CPU:
  2188. MSI_ADDR_REDIRECTION_LOWPRI) |
  2189. MSI_ADDR_DEST_ID(dest);
  2190. msg->data =
  2191. MSI_DATA_TRIGGER_EDGE |
  2192. MSI_DATA_LEVEL_ASSERT |
  2193. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2194. MSI_DATA_DELIVERY_FIXED:
  2195. MSI_DATA_DELIVERY_LOWPRI) |
  2196. MSI_DATA_VECTOR(cfg->vector);
  2197. return err;
  2198. }
  2199. #ifdef CONFIG_SMP
  2200. static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask)
  2201. {
  2202. struct irq_cfg *cfg;
  2203. struct msi_msg msg;
  2204. unsigned int dest;
  2205. cpumask_t tmp;
  2206. cpus_and(tmp, mask, cpu_online_map);
  2207. if (cpus_empty(tmp))
  2208. return;
  2209. if (assign_irq_vector(irq, mask))
  2210. return;
  2211. cfg = irq_cfg(irq);
  2212. cpus_and(tmp, cfg->domain, mask);
  2213. dest = cpu_mask_to_apicid(tmp);
  2214. read_msi_msg(irq, &msg);
  2215. msg.data &= ~MSI_DATA_VECTOR_MASK;
  2216. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  2217. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  2218. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  2219. write_msi_msg(irq, &msg);
  2220. irq_to_desc(irq)->affinity = mask;
  2221. }
  2222. #endif /* CONFIG_SMP */
  2223. /*
  2224. * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
  2225. * which implement the MSI or MSI-X Capability Structure.
  2226. */
  2227. static struct irq_chip msi_chip = {
  2228. .name = "PCI-MSI",
  2229. .unmask = unmask_msi_irq,
  2230. .mask = mask_msi_irq,
  2231. .ack = ack_ioapic_irq,
  2232. #ifdef CONFIG_SMP
  2233. .set_affinity = set_msi_irq_affinity,
  2234. #endif
  2235. .retrigger = ioapic_retrigger_irq,
  2236. };
  2237. static unsigned int build_irq_for_pci_dev(struct pci_dev *dev)
  2238. {
  2239. unsigned int irq;
  2240. irq = dev->bus->number;
  2241. irq <<= 8;
  2242. irq |= dev->devfn;
  2243. irq <<= 12;
  2244. return irq;
  2245. }
  2246. int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
  2247. {
  2248. struct msi_msg msg;
  2249. int irq, ret;
  2250. unsigned int irq_want;
  2251. irq_want = build_irq_for_pci_dev(dev) + 0x100;
  2252. irq = create_irq_nr(irq_want);
  2253. if (irq == 0)
  2254. return -1;
  2255. ret = msi_compose_msg(dev, irq, &msg);
  2256. if (ret < 0) {
  2257. destroy_irq(irq);
  2258. return ret;
  2259. }
  2260. set_irq_msi(irq, desc);
  2261. write_msi_msg(irq, &msg);
  2262. set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq,
  2263. "edge");
  2264. return 0;
  2265. }
  2266. void arch_teardown_msi_irq(unsigned int irq)
  2267. {
  2268. destroy_irq(irq);
  2269. }
  2270. #endif /* CONFIG_PCI_MSI */
  2271. /*
  2272. * Hypertransport interrupt support
  2273. */
  2274. #ifdef CONFIG_HT_IRQ
  2275. #ifdef CONFIG_SMP
  2276. static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
  2277. {
  2278. struct ht_irq_msg msg;
  2279. fetch_ht_irq_msg(irq, &msg);
  2280. msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
  2281. msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
  2282. msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
  2283. msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
  2284. write_ht_irq_msg(irq, &msg);
  2285. }
  2286. static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask)
  2287. {
  2288. struct irq_cfg *cfg;
  2289. unsigned int dest;
  2290. cpumask_t tmp;
  2291. cpus_and(tmp, mask, cpu_online_map);
  2292. if (cpus_empty(tmp))
  2293. return;
  2294. if (assign_irq_vector(irq, mask))
  2295. return;
  2296. cfg = irq_cfg(irq);
  2297. cpus_and(tmp, cfg->domain, mask);
  2298. dest = cpu_mask_to_apicid(tmp);
  2299. target_ht_irq(irq, dest, cfg->vector);
  2300. irq_to_desc(irq)->affinity = mask;
  2301. }
  2302. #endif
  2303. static struct irq_chip ht_irq_chip = {
  2304. .name = "PCI-HT",
  2305. .mask = mask_ht_irq,
  2306. .unmask = unmask_ht_irq,
  2307. .ack = ack_ioapic_irq,
  2308. #ifdef CONFIG_SMP
  2309. .set_affinity = set_ht_irq_affinity,
  2310. #endif
  2311. .retrigger = ioapic_retrigger_irq,
  2312. };
  2313. int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
  2314. {
  2315. struct irq_cfg *cfg;
  2316. int err;
  2317. cpumask_t tmp;
  2318. tmp = TARGET_CPUS;
  2319. err = assign_irq_vector(irq, tmp);
  2320. if ( !err) {
  2321. struct ht_irq_msg msg;
  2322. unsigned dest;
  2323. cfg = irq_cfg(irq);
  2324. cpus_and(tmp, cfg->domain, tmp);
  2325. dest = cpu_mask_to_apicid(tmp);
  2326. msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
  2327. msg.address_lo =
  2328. HT_IRQ_LOW_BASE |
  2329. HT_IRQ_LOW_DEST_ID(dest) |
  2330. HT_IRQ_LOW_VECTOR(cfg->vector) |
  2331. ((INT_DEST_MODE == 0) ?
  2332. HT_IRQ_LOW_DM_PHYSICAL :
  2333. HT_IRQ_LOW_DM_LOGICAL) |
  2334. HT_IRQ_LOW_RQEOI_EDGE |
  2335. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2336. HT_IRQ_LOW_MT_FIXED :
  2337. HT_IRQ_LOW_MT_ARBITRATED) |
  2338. HT_IRQ_LOW_IRQ_MASKED;
  2339. write_ht_irq_msg(irq, &msg);
  2340. set_irq_chip_and_handler_name(irq, &ht_irq_chip,
  2341. handle_edge_irq, "edge");
  2342. }
  2343. return err;
  2344. }
  2345. #endif /* CONFIG_HT_IRQ */
  2346. /* --------------------------------------------------------------------------
  2347. ACPI-based IOAPIC Configuration
  2348. -------------------------------------------------------------------------- */
  2349. #ifdef CONFIG_ACPI
  2350. int __init io_apic_get_unique_id(int ioapic, int apic_id)
  2351. {
  2352. union IO_APIC_reg_00 reg_00;
  2353. static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
  2354. physid_mask_t tmp;
  2355. unsigned long flags;
  2356. int i = 0;
  2357. /*
  2358. * The P4 platform supports up to 256 APIC IDs on two separate APIC
  2359. * buses (one for LAPICs, one for IOAPICs), where predecessors only
  2360. * supports up to 16 on one shared APIC bus.
  2361. *
  2362. * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
  2363. * advantage of new APIC bus architecture.
  2364. */
  2365. if (physids_empty(apic_id_map))
  2366. apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);
  2367. spin_lock_irqsave(&ioapic_lock, flags);
  2368. reg_00.raw = io_apic_read(ioapic, 0);
  2369. spin_unlock_irqrestore(&ioapic_lock, flags);
  2370. if (apic_id >= get_physical_broadcast()) {
  2371. printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
  2372. "%d\n", ioapic, apic_id, reg_00.bits.ID);
  2373. apic_id = reg_00.bits.ID;
  2374. }
  2375. /*
  2376. * Every APIC in a system must have a unique ID or we get lots of nice
  2377. * 'stuck on smp_invalidate_needed IPI wait' messages.
  2378. */
  2379. if (check_apicid_used(apic_id_map, apic_id)) {
  2380. for (i = 0; i < get_physical_broadcast(); i++) {
  2381. if (!check_apicid_used(apic_id_map, i))
  2382. break;
  2383. }
  2384. if (i == get_physical_broadcast())
  2385. panic("Max apic_id exceeded!\n");
  2386. printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
  2387. "trying %d\n", ioapic, apic_id, i);
  2388. apic_id = i;
  2389. }
  2390. tmp = apicid_to_cpu_present(apic_id);
  2391. physids_or(apic_id_map, apic_id_map, tmp);
  2392. if (reg_00.bits.ID != apic_id) {
  2393. reg_00.bits.ID = apic_id;
  2394. spin_lock_irqsave(&ioapic_lock, flags);
  2395. io_apic_write(ioapic, 0, reg_00.raw);
  2396. reg_00.raw = io_apic_read(ioapic, 0);
  2397. spin_unlock_irqrestore(&ioapic_lock, flags);
  2398. /* Sanity check */
  2399. if (reg_00.bits.ID != apic_id) {
  2400. printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
  2401. return -1;
  2402. }
  2403. }
  2404. apic_printk(APIC_VERBOSE, KERN_INFO
  2405. "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
  2406. return apic_id;
  2407. }
  2408. int __init io_apic_get_version(int ioapic)
  2409. {
  2410. union IO_APIC_reg_01 reg_01;
  2411. unsigned long flags;
  2412. spin_lock_irqsave(&ioapic_lock, flags);
  2413. reg_01.raw = io_apic_read(ioapic, 1);
  2414. spin_unlock_irqrestore(&ioapic_lock, flags);
  2415. return reg_01.bits.version;
  2416. }
  2417. int __init io_apic_get_redir_entries(int ioapic)
  2418. {
  2419. union IO_APIC_reg_01 reg_01;
  2420. unsigned long flags;
  2421. spin_lock_irqsave(&ioapic_lock, flags);
  2422. reg_01.raw = io_apic_read(ioapic, 1);
  2423. spin_unlock_irqrestore(&ioapic_lock, flags);
  2424. return reg_01.bits.entries;
  2425. }
  2426. int io_apic_set_pci_routing(int ioapic, int pin, int irq, int triggering, int polarity)
  2427. {
  2428. if (!IO_APIC_IRQ(irq)) {
  2429. printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
  2430. ioapic);
  2431. return -EINVAL;
  2432. }
  2433. /*
  2434. * IRQs < 16 are already in the irq_2_pin[] map
  2435. */
  2436. if (irq >= 16)
  2437. add_pin_to_irq(irq, ioapic, pin);
  2438. setup_IO_APIC_irq(ioapic, pin, irq, triggering, polarity);
  2439. return 0;
  2440. }
  2441. int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
  2442. {
  2443. int i;
  2444. if (skip_ioapic_setup)
  2445. return -1;
  2446. for (i = 0; i < mp_irq_entries; i++)
  2447. if (mp_irqs[i].mp_irqtype == mp_INT &&
  2448. mp_irqs[i].mp_srcbusirq == bus_irq)
  2449. break;
  2450. if (i >= mp_irq_entries)
  2451. return -1;
  2452. *trigger = irq_trigger(i);
  2453. *polarity = irq_polarity(i);
  2454. return 0;
  2455. }
  2456. #endif /* CONFIG_ACPI */
  2457. /*
  2458. * This function currently is only a helper for the i386 smp boot process where
  2459. * we need to reprogram the ioredtbls to cater for the cpus which have come online
  2460. * so mask in all cases should simply be TARGET_CPUS
  2461. */
  2462. #ifdef CONFIG_SMP
  2463. void __init setup_ioapic_dest(void)
  2464. {
  2465. int pin, ioapic, irq, irq_entry;
  2466. struct irq_cfg *cfg;
  2467. struct irq_desc *desc;
  2468. if (skip_ioapic_setup == 1)
  2469. return;
  2470. for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
  2471. for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
  2472. irq_entry = find_irq_entry(ioapic, pin, mp_INT);
  2473. if (irq_entry == -1)
  2474. continue;
  2475. irq = pin_2_irq(irq_entry, ioapic, pin);
  2476. /* setup_IO_APIC_irqs could fail to get vector for some device
  2477. * when you have too many devices, because at that time only boot
  2478. * cpu is online.
  2479. */
  2480. cfg = irq_cfg(irq);
  2481. if (!cfg->vector)
  2482. setup_IO_APIC_irq(ioapic, pin, irq,
  2483. irq_trigger(irq_entry),
  2484. irq_polarity(irq_entry));
  2485. else {
  2486. desc = irq_to_desc(irq);
  2487. set_ioapic_affinity_irq(irq, TARGET_CPUS);
  2488. }
  2489. }
  2490. }
  2491. }
  2492. #endif
  2493. static int __init parse_disable_timer_pin_1(char *arg)
  2494. {
  2495. disable_timer_pin_1 = 1;
  2496. return 0;
  2497. }
  2498. early_param("disable_timer_pin_1", parse_disable_timer_pin_1);
  2499. static int __init parse_enable_timer_pin_1(char *arg)
  2500. {
  2501. disable_timer_pin_1 = -1;
  2502. return 0;
  2503. }
  2504. early_param("enable_timer_pin_1", parse_enable_timer_pin_1);
  2505. static int __init parse_noapic(char *arg)
  2506. {
  2507. /* disable IO-APIC */
  2508. disable_ioapic_setup();
  2509. return 0;
  2510. }
  2511. early_param("noapic", parse_noapic);
  2512. void __init ioapic_init_mappings(void)
  2513. {
  2514. unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
  2515. int i;
  2516. for (i = 0; i < nr_ioapics; i++) {
  2517. if (smp_found_config) {
  2518. ioapic_phys = mp_ioapics[i].mp_apicaddr;
  2519. if (!ioapic_phys) {
  2520. printk(KERN_ERR
  2521. "WARNING: bogus zero IO-APIC "
  2522. "address found in MPTABLE, "
  2523. "disabling IO/APIC support!\n");
  2524. smp_found_config = 0;
  2525. skip_ioapic_setup = 1;
  2526. goto fake_ioapic_page;
  2527. }
  2528. } else {
  2529. fake_ioapic_page:
  2530. ioapic_phys = (unsigned long)
  2531. alloc_bootmem_pages(PAGE_SIZE);
  2532. ioapic_phys = __pa(ioapic_phys);
  2533. }
  2534. set_fixmap_nocache(idx, ioapic_phys);
  2535. printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
  2536. __fix_to_virt(idx), ioapic_phys);
  2537. idx++;
  2538. }
  2539. }